Class Event
Distributed Centralized Event equivalent to asyncio.Event
Declaration
class Event
source linkDocumentation
An event stores a single flag, which is set to false on start.
The flag can be set to true (using the set() call) or back to false
(with the clear() call).
Every call to wait() blocks until the event flag is set to true.
Attributes
- name : string
Name of the event. Choosing the same name allows two
disconnected processes to coordinate an event.
If not given, a random name will be generated.
- client : Client
Client to use for communication with the scheduler.
If not given, the default global client will be used.
Examples
>>> event_1 = Event('a') # doctest: +SKIP
>>> event_1.wait(timeout=1) # doctest: +SKIP
>>> # in another process
>>> event_2 = Event('a') # doctest: +SKIP
>>> event_2.set() # doctest: +SKIP
>>> # now event_1 will stop waiting
Methods
Make it possible to write
>>> event = await Event("x") # doctest: +SKIP
even though no waiting is implied
▷ def __init__(self, name=None, client=None) ▶ def clear(self) Clear the event (set its flag to false).
All waiters will now block.
▷ def is_set(self) Check if the event is set
▶ def set(self) Set the event (set its flag to false).
All waiters will now be released.
▶ def wait(self, timeout=None) Wait until the event is set.
Parameters
- timeout : number or string or timedelta
Seconds to wait on the event in the scheduler. This does not
include local coroutine time, network transfer time, etc..
Instead of number of seconds, it is also possible to specify
a timedelta in string format, e.g. "200ms".
Returns
- True if the event was set of false, if a timeout happend
Examples
>>> event = Event('a') # doctest: +SKIP
>>> event.wait(timeout="1s") # doctest: +SKIP
Reexports