3

我有一个测试脚本可以随机休眠 1 到 180 秒之间的秒数。测试程序将挂起超过 3 分钟。

所以我更改了代码,让它休眠 60 秒(1 分钟)并运行脚本。20 小时后(!!!),代码仍然挂在 time.sleep() 上。

代码是

downtime = 60
time.sleep(downtime)

为什么 Python 在 time.sleep(60) 上永远挂起?

4

3 回答 3

5

You use 2 different variables downtime and downTime. Probably, downTime greater than 60

于 2012-06-05T18:42:04.440 回答
4

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:

  1. You are calling time.sleep() multiple times (e.g. in a loop).
  2. You are calling time.sleep() with an argument that is much higher than 60 (note the two different ways you're spelling downtime/downTime in your code).
  3. The problem has nothing to do with time.sleep().
于 2012-06-05T18:41:48.337 回答
4

灯下一片漆黑。原因可能很荒谬。

检查您是否曾经单击过 shell 屏幕。

在 Powershell 上运行的进程随机冻结

于 2017-09-21T05:18:58.123 回答