Python time.sleep() raises exception in multi-threaded app
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python2.5 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: python2.5-minimal
Ubuntu 7.10
Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
Sometimes, time.sleep() in python raises "IOError: [Errno 22] Invalid argument" in multi-threaded app. This exception is similar to what is raised when sleep()'s argument is non-positive, but it isn't the case. I believe that it happens (rarely) when in another thread an exception is raised (even if it's catched later). It happens both when I call sleep() directly from my code or indirectly from a standard python library (for example threading.Condition class uses sleep, and the bug reproduces with it, too).
Here goes the script with which I reproduce this bug (about two or threee times in ten runs of the script). With the same script at Debian 3.1, python 2.4.1, I can't reproduce the bug (and I believe that it really doesn't happen there).
#!/usr/
import threading, time, random, sys
stopped = False
def do_sleep():
while not stopped:
class MyException(
pass
def do_raise():
while not stopped:
try:
raise MyException
except:
pass
sleepers = [threading.
raisers = [threading.
for s in sleepers: s.start()
for s in raisers: s.start()
for i in range(100):
print ',',
sys.
time.sleep(1)
stopped = True
for s in sleepers: s.join()
for s in raisers: s.join()
print '.'
Changed in python2.5: | |
status: | New → Confirmed |
Yes, and exception (for the script above) looks like this:
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,Exception in thread Thread-81: python2. 5/threading. py", line 460, in __bootstrap python2. 5/threading. py", line 440, in run __target( *self._ _args, **self.__kwargs) sleep(random. random( )/1000 + 0.001)
Traceback (most recent call last):
File "/usr/lib/
self.run()
File "/usr/lib/
self.
File "./threadtest.py", line 8, in do_sleep
time.
IOError: [Errno 22] Invalid argument