Sharing State¶
-
class
usim.Lock[source]¶ Synchronization primitive that may be acquired by only one Activity at a time
Locks enforce mutually exclusive access for Activities, by allowing only one owner at any time. Activities can acquire ownership of a
Lockonly via anasync withcontext, and automatically release when exiting the block:async with lock: ...
Ownership of a lock is inherently tied to a specific activity; it is not possible to acquire and release a
Lockacross several activities. Every lock is re-entrant for its owning activity: an Activity can acquire the same lock multiple times. This allows using Locks safely in recursive calls.-
available¶ Check whether the current Task can acquire this lock
Entering a
Lockin its context manager does not allow backing off when theLockcannot be acquired. Availability of aLockshould be checked if it shall only be acquired when available.if lock.available: # only acquire lock if possible with lock: ... else: ...
-
-
class
usim.Channel[source]¶ Unbuffered stream that broadcasts every message to all consumers
-
await
close()[source]¶ Prevent putting further messages into the
ChannelClosing a
Channelcauses subsequent attempts toput()or retrieve items to fail withStreamClosed.A
Channelcan be closed multiple times; subsequent closes have no effects other than postponement.
-
await
put(item: ST)[source]¶ Put an item into the
Channel- Parameters
item – the item to broadcast
- Raises
StreamClosed – if the stream has been
close()d
-
await
-
class
usim.Queue[source]¶ Buffered stream that anycasts messages to individual consumers
-
await
close()[source]¶ Prevent putting further messages into the
QueueClosing a
Queuecauses subsequent attempts toput()items to fail withStreamClosed. When there are no items in a closedQueue, attempts to retrieve items fail withStreamClosed. Items already buffered may still be received.A
Queuecan be closed multiple times; subsequent closes have no effects other than postponement.
-
await
put(item: ST)[source]¶ Put an item into the
Queue- Parameters
item – the item to enqueue
- Raises
StreamClosed – if the stream has been
close()d
-
await