开发者

Make running python script more responsive to ctrl c?

We are running a very large framework of python scripts for t开发者_如何转开发est automation and I do really miss the opportunity to kill a running python script with ctrl + c in some situations on Windows.

When the script might be doing some socket communications with long time-outs the only options sometimes is to kill the DOS window.. Is there any options I have missed?


Rather than using blocking calls with long timeouts, use event-driven networking. This will allow you never to have long periods of time doing uninterruptable operations.


Look for instances of:

try:
    some code
except:
    # catches all exceptions, including ^C

Change to:

try:
    some code
except Exception:
    # catches most exceptions, but not KeyboardInterrupt or SystemExit
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜