marvis.context
Contexts to tear down the simulation.
Functions
Defer a function call. |
Classes
A context can be used for deferring function calls. |
|
A DeferredItem is used for storing functions calls that need to be executed later on. |
|
The NoContext is a Null-Object and therefore does nothing. |
|
The simple context executes deferred items like it is intented. |
|
- class marvis.context.Context[source]
Bases:
object
A context can be used for deferring function calls.
In this project, it is used for deferring teardowns of the simulation.
You can use it like this:
with SimpleContext() as ctx: defer('Call afunction', afunction, args) defer('Call another function', anotherfunction, args) ctx.cleanup()
- fails
The number of failed cleanups.
- defer(item)[source]
Store a
DeferredItem
for running it later.- Parameters
item (
DeferredItem
) – The function to execute later.
- cancel(item)[source]
Cancel a specific item of the current context.
- Parameters
item (
DeferredItem
) – The function to cancel.
- class marvis.context.DeferredItem(ctx: marvis.context.Context, name: str, func: callable, args, kwargs)[source]
Bases:
object
A DeferredItem is used for storing functions calls that need to be executed later on.
- Parameters
ctx – The context the item belongs to.
name – A name for this item (for logging purposes).
func – The function to defer.
args (list) – The positional arguments to be passed to the function.
kwargs (dict) – The keyword arguments to be passed to the function.
- ctx
The context to execute this item in.
- name
The name of the item (and description).
- func
The callable.
- args
(Positional) Arguments to be passed to the callable.
- kwargs
Keyword arguments to be passed to the callable.
- marvis.context.defer(name, func, *args, **kwargs)[source]
Defer a function call.
The function call be assigned to the current context.
- Parameters
func (callable) – The function to execute.
- class marvis.context.NoContext[source]
Bases:
marvis.context.Context
The NoContext is a Null-Object and therefore does nothing.
It does not do any cleanups. This is useful if you do not want your simulated containers to be torn down.
- defer(item)[source]
Store a
DeferredItem
for running it later.- Parameters
item (
DeferredItem
) – The function to execute later.
- cancel(item)[source]
Cancel a specific item of the current context.
- Parameters
item (
DeferredItem
) – The function to cancel.
- add_error(err: Exception)
Add an error (to be implemented).
- static current()
Return the current context.
- fails
The number of failed cleanups.
- class marvis.context.SimpleContext[source]
Bases:
marvis.context.Context
The simple context executes deferred items like it is intented.
- defer(item)[source]
Store a
DeferredItem
for running it later.- Parameters
item (
DeferredItem
) – The function to execute later.
- cancel(item)[source]
Cancel a specific item of the current context.
- Parameters
item (
DeferredItem
) – The function to cancel.
- add_error(err: Exception)
Add an error (to be implemented).
- static current()
Return the current context.
- fails
The number of failed cleanups.
Inheritance Diagramm