def attach_pyinstrument_profiler():
 profiler = Profiler()
 profiler.start()
 def handle_signal(signum, frame):
  print profiler.output_text(color=True)
  delattr(profiler, '_root_frame')
 signal.signal(signal.SIGTRAP, handle_signal)

def attach_pyinstrument_profiler ( ) : profiler = Profiler ( ) profiler . start ( ) def handle_signal ( signum , frame ) : print profiler . output_text ( color = True ) delattr ( profiler , '_root_frame' ) signal . signal ( signal . SIGTRAP , handle_signal )
run the pyinstrument profiler in the background and dump its output to stdout when the process receives sigtrap .