Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resume code execution from code.interact() in Python

After opening an interactive console while debugging using

code.interact(local=locals())

How can I resume code execution. I have checked the docs for the 'code' module and search stack overflow but cannot find anything.

like image 701
Ibrahim Muhammad Avatar asked Sep 16 '13 19:09

Ibrahim Muhammad


2 Answers

It's the same way you exit any Python interpreter session: send an end-of-file character.

That's Ctrl-D on Linux or Ctrl-Z Enter on Windows.

like image 71
kindall Avatar answered Nov 15 '22 06:11

kindall


If like me you always forget to hit Ctrl-D, you can wrap up your prompt in a try/except block:

try:
    code.interact(local=locals())
except SystemExit:
    pass
like image 36
Cody Piersall Avatar answered Nov 15 '22 05:11

Cody Piersall