Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you exit PDB /and/ kill the program?

Tags:

python

pdb

How do you kill PDB and the program it's running, similar to LLDB's proc kill; exit or exit (y) commands?

Ctrl+D isn't working and all the questions I see on here are how to exit while keeping the program running. However, I'm sitting in a PDB session and I found a bug that is causing an endless loop, and while there are indeed other things I can do to kill the program I figured I'd ask what the PDB command is to do it.

like image 929
Qix - MONICA WAS MISTREATED Avatar asked May 01 '17 09:05

Qix - MONICA WAS MISTREATED


1 Answers

The pdb command to kill the program is q, or quit. Quoting the docs:

q(uit)
Quit from the debugger. The program being executed is aborted.

When q is not enough to stop the loop (perhaps you have a misbehaving except block), you may need to use os._exit(), a low-level command which terminates the process immediately. (q and sys.exit work by throwing exceptions - bdb.BdbQuit for q and SystemExit for sys.exit.) os._exit will prevent any finally blocks or __exit__ methods from running, so you may have to deal with data corruption or data loss.

Ex: import os; os._exit(0)

(https://stackoverflow.com/a/38511414/2036148)

like image 109
Edvard Rejthar Avatar answered Oct 25 '22 19:10

Edvard Rejthar