我有一个测试脚本可以随机休眠 1 到 180 秒之间的秒数。测试程序将挂起超过 3 分钟。
所以我更改了代码,让它休眠 60 秒(1 分钟)并运行脚本。20 小时后(!!!),代码仍然挂在 time.sleep() 上。
代码是
downtime = 60
time.sleep(downtime)
为什么 Python 在 time.sleep(60) 上永远挂起?
You use 2 different variables downtime and downTime. Probably, downTime greater than 60
Even though time.sleep()
is permitted to suspend your thread for an interval that is shorter, or longer, than what you ask, time.sleep(60)
would not suspend your thread for 20 hours.
I can see several possible explanations:
time.sleep()
multiple times (e.g. in a loop).time.sleep()
with an argument that is much higher than 60 (note the two different ways you're spelling downtime
/downTime
in your code).time.sleep()
.