marvis.context

Contexts to tear down the simulation.

Functions

defer

Defer a function call.

Classes

Context

A context can be used for deferring function calls.

DeferredItem

A DeferredItem is used for storing functions calls that need to be executed later on.

NoContext

The NoContext is a Null-Object and therefore does nothing.

SimpleContext

The simple context executes deferred items like it is intented.

ThreadLocalStack


class marvis.context.ThreadLocalStack[source]

Bases: object

property stack
push(item)[source]
pop()[source]
top()[source]
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()
static current()[source]

Return the current context.

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.

cleanup()[source]

Do whatever is needed to cleanup the context.

add_error(err: Exception)[source]

Add an error (to be implemented).

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.

cancel()[source]

Cancel the execution of the item.

cleanup()[source]

Execute the function call.

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.

cleanup()[source]

Do whatever is needed to cleanup the context.

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.

cleanup()[source]

Do whatever is needed to cleanup the context.

add_error(err: Exception)

Add an error (to be implemented).

static current()

Return the current context.

fails

The number of failed cleanups.

Inheritance Diagramm

Inheritance diagram of marvis.context