How do you break into the debugger from Python source code?
import pdb; pdb.set_trace() See Python: Coding in the Debugger for Beginners for this and more helpful hints.
import pdb; pdb.set_trace() See Python: Coding in the Debugger for Beginners for this and more helpful hints.
You’re probably looking for the s command: it s-teps into the next function. While in debugging mode, you can see all available commands using h (help). See also the docs.
No, python2’s pdb doesn’t support this, but you add this code to your program as a workaround: def debug_signal_handler(signal, frame): import pdb pdb.set_trace() import signal signal.signal(signal.SIGINT, debug_signal_handler) Related questions: Showing the stack trace from a running Python application enter pdb with kill signal
A possible solution/workaround is to run globals().update(locals()) before running the list comprehension in (i)pdb.
Another option is to create you own Pdb object, and set there the stdin and stdout. My proof of concept involves 2 terminals, but for sure some work can be merged some kind of very unsecure network server. Create two fifos: mkfifo fifo_stdin mkfifo fifo_stdout In one terminal, open stdout on background, and write to … Read more
As the user @ffeast commented, there is an open ipdb issue, and a few workarounds suggested. For me these worked well: press ctrl+z and kill %1 (or whatever the Job number is) execute ipdb> import os; os._exit(1)
I had a similar problem debugging the useage of aiofile. I then found a solution using nest_asyncio. For example if one has the following async example script: import asyncio from aiofile import async_open import nest_asyncio async def main(): async with async_open(“/tmp/hello.txt”, ‘w+’) as afp: await afp.write(“Hello “) await afp.write(“world”) afp.seek(0) breakpoint() print(await afp.read()) if __name__==”__main__”: … Read more
You can’t do it now, because -m terminates option list python -h … -m mod : run library module as a script (terminates option list) … That means it’s mod’s job to interpret the rest of the arguments list and this behavior fully depends on how mod is designed internally and whether it support another … Read more
The command d is the command for the debugger used to go down the stack to a ‘newer frame’. It seems that the parsing cannot not handle this disambiguity. Try renaming the variable d. EDIT: Actually, the comments suggest much better handling than renaming.
Sending an EOF by pressing Ctrl + D should work: $ python -m pdb myscript.py > …/myscript.py(1)<module>() -> import os (Pdb) import code (Pdb) code.interact() Python 2.7.11 (default, Dec 27 2015, 01:48:39) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. (InteractiveConsole) >>> <CTRL-D> (Pdb) c … Read more