Reputation: 372
I have a test script that sleeps for a random amount of seconds, between 1 and 180 seconds. The test program would hang for more than 3 minutes.
So I changed the code so that it would sleep for 60 seconds (1 minute) and ran the script. After 20 hours (!!!), the code is still hanging on time.sleep().
The code is
downtime = 60
time.sleep(downtime)
Why does Python hang forever on a time.sleep(60)?
Upvotes: 5
Views: 10472
Reputation: 3433
In my case, I had commented some lines and introduced a bug due to a missing variable. For example:
# Some_code...
# my_var = True
time.sleep(1)
return my_var
This was not a hang due to sleep()
but rather an error that was occurring in the worker nodes and the master node never got a response, waiting for a result that was never going to arrive. Checking the logs of the workers I could see the error and correct it.
Upvotes: 1
Reputation: 14789
It is dark under the lamp. The reason could be ridiculous.
Check if you ever clicked the shell screen.
Processes running on Powershell freezes randomly
Upvotes: 6
Reputation: 18358
You use 2 different variables downtime and downTime. Probably, downTime greater than 60
Upvotes: 5
Reputation: 500317
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()
.Upvotes: 4