trame.app.asynchronous module

trame.app.asynchronous.create_task(coroutine, loop=None)

Create a task from a coroutine while also attaching a done callback so any exception or error could be caught and reported.

Parameters:
  • coroutine – A coroutine to execute as an independent task

  • loop – Optionally provide the loop on which the task should be scheduled on. By default we will use the current running loop.

Returns:

The decorated task

Return type:

asyncio.Task

trame.app.asynchronous.decorate_task(task)

Decorate a task by attaching a done callback so any exception or error could be caught and reported.

Parameters:

task (asyncio.Task) – A coroutine to execute as an independent task

Returns:

The same task object

Return type:

asyncio.Task

trame.app.asynchronous.task(func)

Function decorator to make its async execution within a task

class trame.app.asynchronous.StateQueue(queue, auto_flush=True)

Bases: object

Class use to decorate a multiprocessing.Queue inside your external process to simulate your server state object.

Parameters:
  • queue (multiprocessing.Queue) – A queue instance meant to exchange state from the parallel process to the given server

  • auto_flush (Boolean) – Should you manage the state update phase or just propagate as soon as you update a property

property queue

Provide access to the decorated queue

update(_dict)

Update the distributed state from a set of key/value pair

Parameters:

_dict (dict) – A dict containing one or many key/value pair

flush()

Explicitly push any local change to the queue.

exit()

Release the monitoring task as we are done with our work

trame.app.asynchronous.create_state_queue_monitor_task(server, queue, delay=1)

Create and schedule a task to watch over the provided queue to update a server state. This is especially useful when using a multiprocess executor and you want to report progress into your current server.

Parameters:
  • server (trame_server.core.Server) – A coroutine to execute as an independent task

  • queue (multiprocessing.Queue) – A queue instance meant to exchange state from the parallel process to the given server

  • delay (float) – Time to sleep in seconds before processing the queue once emptied

Returns:

The monitoring task

Return type:

asyncio.Task