pause/resume a python script in middle

后端 未结 9 1543
再見小時候
再見小時候 2020-12-28 16:38

Can I have a running python script(under Windows)being paused in the middle by user , and resume again when user decides ?

There is a main manager program which gen

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-28 17:23

    I found so hacky those responses, while being interesting too.

    The best approach is the https://stackoverflow.com/a/7184165/2480481 doing it using KeyboardInterrupt exception.

    As i noticed nobody mention "using a debugger", i'll do it.

    Install pdb, Python debugger with pip install pdb. Follow that to make your script pausable https://stackoverflow.com/a/39478157/2480481 by Ctrl+c instead of exit it.

    The main benefit of using a debugger (pdb) is that you can inspect the variables, values, etc. This is far way more powerfull than just pause/continue it.

    Also, you can add Ipython interface with pdb attached to debug your app when crashes. Look at: https://stackoverflow.com/a/14881323/2480481

提交回复
热议问题