* nix python信令允許我在睡眠準備就緒之前停止睡眠。在Windows中是否有類似的機制 - 似乎所有的方法最終只能在睡眠之後攔截代碼?有沒有辦法停止Windows中的time.sleep?
代碼示例:
from time import sleep
.. do something that will intercept the sleep
try:
sleep(60)
finally:
print 'how to get here under 60 seconds in windows?'
在沒有窗戶的回答類似的問題: break/interrupt a time.sleep() in python
爲signal
你可以編寫代碼,等待一個'threading.Event',超時時間爲60秒,如果你想取消等待,從另一個線程中選擇該事件? –
首先閱讀解析經典標點符號的句子。希望有一種方法可以通過在某個地方睡覺來停止時間。 – Simon
這不是我的代碼。這是未知的客戶端代碼,我試圖超時發生後停止。看來,在cpython中沒有真正好的機制存在..是的,我們也嘗試過線程和子進程是不行的。 – mkorpela