This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Event spends less time in wait() than requested
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ddvoinikov, pitrou
Priority: normal Keywords:

Created on 2010-09-18 12:58 by ddvoinikov, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg116772 - (view) Author: Dmitry Dvoinikov (ddvoinikov) Date: 2010-09-18 12:58
If you request Event.wait(x), the call consistently returns in less than x seconds.

Sample:
---------------------------------------------------------
from threading import Event
from time import time

e = Event()

before = time()
e.wait(0.1)
after = time()

print(after - before)

# under Python 3.1 prints 0.109999...
# under Python 3.2 prints 0.092999...
---------------------------------------------------------
msg116782 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-18 14:20
It consistently doesn't here:
0.10013985633850098
0.1001589298248291
(etc.)

What system are you using? There are two factors:
- accuracy of the timeout in the wait() function
- accuracy of the results returned by time()

Apart from a possible bug in Python, both of these factors depend on the operating system.
msg116799 - (view) Author: Dmitry Dvoinikov (ddvoinikov) Date: 2010-09-18 15:31
You are right, sorry. It's Windows XP Prof, Python 3.2a2.

The differences in OS may be the cause, but the problem doesn't appear in 3.1 on the same machine.
msg116803 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-18 15:50
> You are right, sorry. It's Windows XP Prof, Python 3.2a2.
> 
> The differences in OS may be the cause, but the problem doesn't appear
> in 3.1 on the same machine.

The implementation changed between 3.1 and 3.2. On 3.1, wait() with
timeout ran a polling loop until either the event was set or the delay
was expired (and it used time() itself, which kind of guarantees that
your case would always produce the expected result).

On 3.2, wait() with timeout simply calls the adequate OS function
(sem_timedwait under POSIX, WaitForSingleObject under Windows). It is
actually more precise, because the polling loop and its sleep() calls
are eliminated.

Also, I just traced the WaitForSingleObject call under a Windows VM, and
it gets called with the correct timeout value (100 ms).
msg116810 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-18 16:20
I'm closing because there doesn't seem to be a genuine bug in Python. But thanks for reporting anyway! The threading facilities in 3.2 need real-world testing.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54101
2010-09-18 16:20:55pitrousetstatus: open -> closed
resolution: not a bug
messages: + msg116810
2010-09-18 15:50:57pitrousetmessages: + msg116803
2010-09-18 15:31:53ddvoinikovsetmessages: + msg116799
2010-09-18 14:20:54pitrousetnosy: + pitrou
messages: + msg116782
2010-09-18 12:58:09ddvoinikovcreate