signal.alarm replacement in Windows [Python]

后端 未结 4 600
情深已故
情深已故 2020-12-03 20:53

I have a function that occasionally hangs.

Normally I would set an alarm, but I\'m in Windows and it\'s unavailable.

Is there a simple way around this, or sh

4条回答
  •  难免孤独
    2020-12-03 21:44

    The most robust solution is to use a subprocess, then kill that subprocess. Python2.6 adds .kill() to subprocess.Popen().

    I don't think your threading approach works as you expect. Deleting your reference to the Thread object won't kill the thread. Instead, you'd need to set an attribute that the thread checks once it wakes up.

提交回复
热议问题