简体   繁体   中英

While running a Python Flask service in PDB, how do you pause/interrupt?

I'm currently trying to debug memory usage of a python flask program, and I'm able to run the program in PDB by adding:

import pdb
pdb.set_trace()

At the entry point of my server. Then I tell PDB to continue and run the program.

I've read that by doing Ctrl-C, I can pause a program running in PDB, but it appears Flask is catching the KeyboardInterrupt exception:

^CKeyboardInterrupt
Traceback (most recent call last):
  File "./server.py", line 4, in <module>
    from mauie.defaults import *
  File "/lib/python2.7/site-packages/flask_socketio/__init__.py", line 414, in run
  File "/lib/python2.7/site-packages/gevent/baseserver.py", line 284, in serve_forever
  File "/lib/python2.7/site-packages/gevent/event.py", line 77, in wait
  File "/lib/python2.7/site-packages/gevent/hub.py", line 338, in switch
KeyboardInterrupt

But the PDB prompt never comes up.

set_trace() is simply a Python function, so you can call it at any point in your code. Have you considered simply adding additional breakpoints to your code and looking at the memory that way?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM