How to debug long running python scripts or servic

2020-06-04 07:33发布

问题:

Pretty much what the title says, I would like to be able to connect to a python process running under paster or uwsgi and utilize pdb functionality.

回答1:

Using winpdb, you can attach to a running process like this:

  1. Insert

    import rpdb2; rpdb2.start_embedded_debugger('mypassword')
    

    inside your script.

  2. Launch your script (through paster or uwsgi) as usual.
  3. Run winpdb
  4. Click File>Attach
  5. Type in password (e.g. "mypassword"), select the process.
  6. To detach, click File>Detach. The script will continue to run, and can be attached to again later.