~ubuntu-branches/ubuntu/lucid/paramiko/lucid

« back to all changes in this revision

Viewing changes to paramiko/sigquit.py

  • Committer: Bazaar Package Importer
  • Author(s): Adeodato Simó
  • Date: 2008-01-24 13:54:18 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124135418-npxfwu271vsfsa3c
Tags: 1.7.2-0.1
* Non-maintainer upload to DELAYED/14-day. (¹)
* New upstream release. (Closes: #415060)
* Drop the patch introduced in 1.6.4-1.1, as it's part of 1.7.2.

  (¹) Counting since the initial 1.7.1-0.1 upload in Jan 13th.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
import atexit
4
 
import signal
5
 
import sys
6
 
import threading
7
 
import time
8
 
 
9
 
_trace = {}
10
 
 
11
 
 
12
 
def stacktrace_line(frame):
13
 
    return '%s:%s (in %s)' % (frame.f_code.co_name, frame.f_lineno, frame.f_code.co_filename)
14
 
 
15
 
def dump_trace(frame):
16
 
    out = []
17
 
    while frame is not None:
18
 
        out.append('    ' + stacktrace_line(frame))
19
 
        frame = frame.f_back
20
 
    return '\n'.join(out)
21
 
 
22
 
def tracer(frame, kind, obj):
23
 
    global _trace
24
 
    _trace[threading.currentThread()] = frame
25
 
    if (kind != 'exception') and (kind != 'c_exception') and kind != 'c_call' and kind != 'c_return':
26
 
        return tracer
27
 
 
28
 
def dump_thread(thread):
29
 
    global _trace
30
 
    out = [ 'Stack trace for thread %r:' % (thread,) ]
31
 
    frame = _trace.get(thread, None)
32
 
    if frame is None:
33
 
        out.append('    <unable to find stack trace>')
34
 
    else:
35
 
        out.append(dump_trace(frame))
36
 
    return '\n'.join(out)
37
 
 
38
 
def sigquit(signal, frame):
39
 
    sys.stderr.write('\nSIGQUIT - THREAD STACKS:\n')
40
 
    for thread in threading.enumerate():
41
 
        sys.stderr.write('\n')
42
 
        sys.stderr.write(dump_thread(thread))
43
 
    sys.stderr.write('\n')
44
 
 
45
 
 
46
 
#sys.settrace(tracer)
47
 
#threading.settrace(tracer)
48
 
sys.setprofile(tracer)
49
 
threading.setprofile(tracer)
50
 
#atexit.register(lambda: sys.settrace(None))
51
 
atexit.register(lambda: sys.setprofile(None))
52
 
signal.signal(signal.SIGQUIT, sigquit)