Event::wait with timeout gives delay
okko.willeboordse at gmail.com
Sun Feb 9 12:53:04 CET 2014
Running Python 2.6 and 2.7 on Windows 7 and Server 2012
Event::wait causes a delay when used with a timeout that is not triggered because event is set in time. I don't understand why.
Can someone explain?
The following program shows this;
'''Shows that using a timeout in Event::wait (same for Queue::wait) causes a delay.
This is perhaps caused by a polling loop inside the wait implementation.
This polling loop sleeps some time depending on the timeout.
Probably wait timeout > 1ms => sleep = 1ms
A wait with timeout can take at least this sleep time even though the event is set or queue
filled much faster.'''
event1 = threading.Event()
event2 = threading.Event()
'''wait 4 event2, clear event2 and set event1.'''
receiver_thread = threading.Thread(target = receiver)
'''Performs a transaction; clear event1, set event2 and wait for thread to set event1.'''
event1.wait(timeout = timeout)
# With timeout None this runs fast and CPU bound.
# With timeout set to some value this runs slow and not CPU bound.
do_transaction(timeout = 10.0)
More information about the Python-list