我正在使用非常标准的Threading.Event:主线程在一个循环中运行:
event.wait(60)
Run Code Online (Sandbox Code Playgroud)
其他阻止请求,直到回复可用,然后启动:
event.set()
Run Code Online (Sandbox Code Playgroud)
我希望主线程选择40秒,但事实并非如此.从Python 2.7源代码Lib/threading.py:
# Balancing act: We can't afford a pure busy loop, so we
# have to sleep; but if we sleep the whole timeout time,
# we'll be unresponsive. The scheme here sleeps very
# little at first, longer as time goes on, but never longer
# than 20 times per second (or the timeout time remaining).
endtime = _time() + timeout
delay = 0.0005 # 500 us -> initial delay of 1 ms
while …Run Code Online (Sandbox Code Playgroud)