1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
import os
import sys
import manhole
stack_dump_file = '/tmp/manhole-pid'
uwsgi_signal_number = 17
try:
import uwsgi
if not os.path.exists(stack_dump_file):
open(stack_dump_file, 'w')
def open_manhole(dummy_signum):
with open(stack_dump_file) as fh:
pid = fh.read().strip()
if pid == str(os.getpid()):
inst = manhole.install(strict=False, thread=False)
inst.handle_oneshot(dummy_signum, dummy_signum)
uwsgi.register_signal(uwsgi_signal_number, 'workers', open_manhole)
uwsgi.add_file_monitor(uwsgi_signal_number, stack_dump_file)
print(f'Listening for stack manhole requests via {stack_dump_file!r}', file=sys.stderr)
except ImportError:
print('Not running under uwsgi; unable to configure manhole trigger', file=sys.stderr)
except OSError:
print(f'IOError creating manhole trigger {stack_dump_file!r}', file=sys.stderr)
def application(env, sr):
sr('200 OK', [('Content-Type', 'text/plain'), ('Content-Length', '2')])
yield b'OK'
|