Revision d509e6da

b/Changelog
6 6
Since v0.13 most of the Synnefo components have been merged into a single
7 7
repository and have aligned versions.
8 8

  
9
.. _Changelog-0.14.3:
10

  
11
v0.14.3
12
=======
13

  
14
Synnefo-wide
15
------------
16

  
17
* Use the SYNNEFO_TRACE environmental variable to control whether the greenlet
18
  tracing code will get loaded or not.
19

  
20
Released: UNRELEASED
21

  
9 22
.. _Changelog-0.14.2:
10 23

  
11 24
v0.14.2
b/snf-common/synnefo/lib/trace.py
1
# Copyright 2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34

  
35
def set_signal_trap():
36
    from os import getpid
37
    from traceback import format_stack, print_exc
38
    from signal import signal, SIGTRAP
39
    from sys import stderr
40
    import gc
41

  
42
    def greenlet_trace(arg):
43
        i = 0
44
        stderr.write("--- Greenlet trace: %s\n" % arg)
45
        for ob in gc.get_objects():
46
            if not isinstance(ob, greenlet):
47
                continue
48
            if not ob:
49
                continue
50
            i = i + 1
51
            stderr.write(("--- > Greenlet %d:\n" % i +
52
                          "".join(format_stack(ob.gr_frame)) + "\n\n"))
53
        stderr.write("--- End of trace: %s\n" % arg)
54

  
55
    try:
56
        from greenlet import greenlet
57
    except ImportError:
58

  
59
        def greenlet_trace(arg):
60
            return
61

  
62
    def handle_trap(*args):
63
        try:
64
            import trap_inject
65
            reload(trap_inject)
66
            trap_inject.inject()
67
        except ImportError:
68
            pass
69
        except:
70
            print_exc()
71

  
72
        msg = ('=== pid: %s' % getpid()) + '\n'.join(format_stack()) + '\n'
73
        stderr.write(msg)
74
        greenlet_trace('TRAP')
75

  
76
    signal(SIGTRAP, handle_trap)
b/snf-common/synnefo/settings/__init__.py
57 57
        conffiles = [f for f in entries if os.path.isfile(f) and
58 58
                     f.endswith(".conf")]
59 59
    except Exception as e:
60
        print >>sys.stderr, "Failed to list *.conf files under %s" % \
61
                            SYNNEFO_SETTINGS_DIR
60
        print >> sys.stderr, "Failed to list *.conf files under %s" % \
61
                             SYNNEFO_SETTINGS_DIR
62 62
        raise SystemExit(1)
63 63
    conffiles.sort()
64 64
    for f in conffiles:
65 65
        try:
66 66
            execfile(os.path.abspath(f))
67 67
        except Exception as e:
68
            print >>sys.stderr, "Failed to read settings file: %s [%r]" % \
69
                                (os.path.abspath(f), e)
68
            print >> sys.stderr, "Failed to read settings file: %s [%r]" % \
69
                                 (os.path.abspath(f), e)
70 70
            raise SystemExit(1)
71

  
72

  
73
from os import environ
74
# The tracing code is enabled by an environmental variable and not a synnefo
75
# setting, on purpose, so that you can easily control whether it'll get loaded
76
# or not, based on context (eg enable it for gunicorn but not for eventd).
77
if environ.get('SYNNEFO_TRACE'):
78
    from synnefo.lib import trace
79
    trace.set_signal_trap()

Also available in: Unified diff