- class usim.typing.BorrowedResources(resources: usim._basics.resource.BaseResources, debits: usim._basics._resource_level.ResourceLevels)
Fixed supply of named resources temporarily taken from another resource supply
- borrow(**amounts: usim._basics.resource.T) usim._basics.resource.BorrowedResources[usim._basics.resource.T]
Temporarily borrow resources for a given context
amounts – resource levels to borrow
async context to borrow resources
- property limits
Upper limit of resource levels
- class usim.typing.ClaimedResources(resources: usim._basics.resource.BaseResources, debits: usim._basics._resource_level.ResourceLevels)
Fixed supply of resources temporarily taken without delay
- class usim.typing.Condition
An asynchronous logical condition
Conditioncan be used both in an asynchronous and boolean context. In an asynchronous context, such as
Conditiontriggers when the
True. In a boolean context, such as
Conditionprovides its current boolean value.
if condition: # resume with current value print(condition, 'is met') else: print(condition, 'is not met') await condition # resume when condition is True async with until(condition): # interrupt when condition is True ...
Conditionsupports the bitwise operators
a & b(and), as well as
a | b(or) to derive a new
Condition. While it is possible to use the boolean operators
and, as well as
or, they immediately evaluate any
Conditionin a boolean context.
await (a & b) # resume when both a and b are True await (a | b) # resume when one of a or b are True await (a & ~b) # resume when a is True and b is False c = a & b # derive new Condition... await c # that can be awaited d = a and b # force boolean evaluation
- class usim.typing.Notification
Synchronisation point to which activities can subscribe
await notification # hibernate until notified async with until(notification): ...
- class usim.typing.ResourceLevels(**kwargs: usim._basics._resource_level.T)
Common class for named resource levels
Representation for the levels of multiple named resources. Every set of resources, such as
usim.Capacities, specializes a
ResourceLevelssubclass with one attribute for each named resource. For example,
Resources(a=3, b=4)uses a
from usim import Resources resources = Resources(a=3, b=4) print(resources.levels.a) # 3 print(resources.levels.b) # 4 print(resources.levels.c) # raises AttributeError
ResourceLevelssubtypes allow no additional attributes other than their initial resources, but their values may be changed. Instantiating a subtype requires resource levels to be specified by keyword; missing resource are set to zero.
Each resource always uses the same
ResourceLevelssubtype. Binary operators for comparisons and arithmetic can be applied for instances of the same subtype.
- levels_a + levels_b
- levels_a - levels_b
Elementwise addition/subtraction of values.
- levels_a > levels_b
- levels_a >= levels_b
- levels_a <= levels_b
- levels_a < levels_b
- levels_a == levels_b
- levels_a != levels_b
- for field, value in levels_a
Iterate over the current
- class usim.typing.Task(payload: Coroutine[Any, Any, usim._primitives.task.RT], parent: Scope, delay: Optional[float], at: Optional[float], volatile: bool)
Concurrently running activity
payloadactivity that is concurrently run in a
Scope. This allows to store or pass on the
Taskin order to control the underlying activity. Other activities can
Taskto receive results or exceptions on completion, similar to a regular activity.
async def my_activity(delay): await (time + delay) return delay await my_activity() # await an activity async with Scope() as scope: task = scope.do(my_activity()) await task # await Task of an activity
In contrast to a bare activity, it is possible to
awaitthe result of a
Taskmultiple times, and
This class should not be instantiated directly. Always use a
Scopeto create it.
- cancel(*token) None
Cancel this task during the current time step
CancelTaskis raised, the cancellation is ignored. This also means that cancelling an activity multiple times is allowed, but only the first successful cancellation is stored as the cancellation cause.
Taskhas not started running, it is cancelled immediately. This prevents any code execution, even before the first suspension.
The timing of cancelling a Task before it started running may change in the future.
- property done: usim._primitives.task.Done
Taskhas stopped running. This includes completion, cancellation and failure.
- property status: usim._primitives.task.TaskState
The current status of this activity