Skip to content

Instantly share code, notes, and snippets.

@SonOfLilit
Created May 22, 2014 15:27
Show Gist options
  • Save SonOfLilit/ad0a90b14cfad96badaf to your computer and use it in GitHub Desktop.
Save SonOfLilit/ad0a90b14cfad96badaf to your computer and use it in GitHub Desktop.
Python bug?
"""
$ python event_test.py
Traceback (most recent call last):
File "event_test.py", line 14, in <module>
assert value
AssertionError
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
"""
from threading import Thread, Event
event = Event()
class Toggler(Thread):
daemon = True
def run(self):
while True:
event.set()
event.clear()
Toggler().start()
while True:
value = event.wait()
assert value
@SonOfLilit
Copy link
Author

https://docs.python.org/2/library/threading.html#threading.Event.wait

wait([timeout])
Block until the internal flag is true. If the internal flag is true on entry, return immediately. Otherwise, block until another thread calls set() to set the flag to true, or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof).

This method returns the internal flag on exit, so it will always return True except if a timeout is given and the operation times out.

Changed in version 2.7: Previously, the method always returned None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment