EventActorο
- class bapsf_motion.actors.base.EventActor(*, name: str = None, logger: Logger = None, loop: AbstractEventLoop = None, auto_run: bool = False, parent: EventActor | None = None)ο
-
A base class for any Actor that will be interacting with an
asncioevent loop.- Parameters:
name (str, optional) β A unique
namefor the Actor instance.logger (
Logger, optional) β The instance ofLoggerthat the Actor should record events and status updates.loop (
asyncio.AbstractEventLoop, optional) β Instance of anasyncioevent loop. IfNone, then an event loop will be auto-generated. (DEFAULT:None)auto_run (bool, optional) β If
True, then the event loop will be placed in a separate thread and started. This is all done via therun()method. (DEFAULT:False)
Attributes Summary
Configuration dictionary of the actor.
The
Loggerinstance being used for the actor.The
asyncioevent loop for the actor.(
str) A unique name given for the instance of the actor.List of
asyncio.Tasks this actor has in its event loop.Indicates if the actor has been terminated.
The
Threadthe event loop is running in.Methods Summary
run([auto_run])Activate the
asyncioevent loop.setup_event_loop([loop])Set up the
asyncioevent 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
Loggerinstance being used for the actor.
- loopο
The
asyncioevent 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 (seelogger).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
Threadthe event loop is running in.If
loopwas given during instantiation, then there is no way of obtaining the thread object the event loop is running in. In this casethreadwill beNone.The thread id can always be retrieved using
_thread_id.
Methods Documentation
- run(auto_run=True)ο
Activate the
asyncioevent loop. If the event loop is running, then nothing happens. Otherwise, the event loop is placed in a separate thread and set torun_forever.
- setup_event_loop(loop: AbstractEventLoop | None = None)ο
Set up the
asyncioevent loop. If the given loop is not an instance ofAbstractEventLoop, then a new loop will be created.- Parameters:
loop (
asyncio.AbstractEventLoop) βasyncioevent 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)