Using time.sleep() in 2 threads causes lockup when hyper-threading is enabled

Serge Orlov Serge.Orlov at gmail.com
Wed May 3 17:11:11 EDT 2006


OlafMeding at gmail.com wrote:
> > What do you mean "stop responding"?
>
> Both threads print their thread numbers (either 1 or 2) approximately
> every 10 seconds.  However, after a while (minutes to hours) both
> programs (see above) hang!
>
> Pressing ctrl-c (after the printing stops) causes the threads to "wake
> up" from their sleep statement.  And since the sleep took more than 1
> seconds the thread number and the duration of the sleep is printed to
> the screen.
>
> Do you have a hyper-threading/dual/multi core CPU?  Did you try this?

I don't have such CPU but I run the first program anyway. It printed

C:\py>th.py
thread 1 started
sleep time: 0.01
3.63174649292e-006
8.43682646817e-005
0.000164825417756

thread 2 started
sleep time: 0.003
0.000675225482568
0.000753447714724
0.00082943502596

1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 2 1

I got bored and tried to stop it with ctrl-c but it didn't respond and
kept running and printing the numbers. I had to kill it from task
manager.




More information about the Python-list mailing list