EventActor

class bapsf_motion.actors.base.EventActor(*, name: str = None, logger: Logger = None, loop: AbstractEventLoop = None, auto_run: bool = False, parent: EventActor | None = None)

Bases: BaseActor, ABC

A base class for any Actor that will be interacting with an asncio event loop.

Parameters:

Attributes Summary

config

Configuration dictionary of the actor.

logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

name

(str) A unique name given for the instance of the actor.

parent

tasks

List of asyncio.Tasks this actor has in its event loop.

terminated

Indicates if the actor has been terminated.

thread

The Thread the event loop is running in.

Methods Summary

run([auto_run])

Activate the asyncio event loop.

setup_event_loop([loop])

Set up the asyncio event loop.

terminate([delay_loop_stop])

Stop the actor's event loop.

Attributes Documentation

config

Configuration dictionary of the actor.

Warning

This dictionary should never be written to from outside the owning actor.

logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

name

(str) A unique name given for the instance of the actor. This name is used as an identifier in the actor logger (see logger).

If the user does not specify a name, then the Actor should auto-generate a name.

parent
tasks

List of asyncio.Tasks this actor has in its event loop.

terminated

Indicates if the actor has been terminated.

thread

The Thread the event loop is running in.

If loop was given during instantiation, then there is no way of obtaining the thread object the event loop is running in. In this case thread will be None.

The thread id can always be retrieved using _thread_id.

Methods Documentation

run(auto_run=True)

Activate the asyncio event loop. If the event loop is running, then nothing happens. Otherwise, the event loop is placed in a separate thread and set to run_forever.

Parameters:

auto_run (bool, optional) – If False, then do NOT start the event loop. This keyword is only made available to help with subclassing. (DEFAULT: True)

setup_event_loop(loop: AbstractEventLoop | None = None)

Set up the asyncio event loop. If the given loop is not an instance of AbstractEventLoop, then a new loop will be created.

Parameters:

loop (asyncio.AbstractEventLoop) – asyncio event loop for the actor’s tasks

terminate(delay_loop_stop=False)

Stop the actor’s event loop. All actor tasks will be cancelled, the connection to the motor will be shutdown, and the event loop will be stopped.

Parameters:

delay_loop_stop (bool) – If True, then do NOT stop the event loop. In this case it is assumed the calling functionality is managing additional tasks in the event loop, and it is up to that functionality to stop the loop. (DEFAULT: False)