Issue
There seem to be many, many threads here and Google hits re use of exit, quit, os._exit(), sys.exit() in Python, but none I've found play nicely with IPython.
When I use most of them I get:
UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
I'm trying to debug in Python - when a certain condition is met I want Python to stop executing and return to the Python command line so I can examine global variables, etc.
How to do that?
For now I've done this, which works when I hit Ctrl-C, but there ought to be a way that doesn't require the Ctrl-C.
def halt():
while True:
time.sleep(0.2)
Solution
Have you tried using the Python Debugger?
import pdb
while doing_something:
if condition:
pdb.set_trace()
If you want to manually control when the loop exits, you can try:
while doing_something:
try:
do_something()
except KeyboardInterrupt:
pdb.set_trace()
Answered By - Mike McCartin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.