mode.threads

ServiceThread - Service that starts in a separate thread.

Will use the default thread pool executor (loop.set_default_executor()), unless you specify a specific executor instance.

Note: To stop something using the thread’s loop, you have to use the on_thread_stop callback instead of the on_stop callback.

class mode.threads.QueuedMethod

Describe a method to be called by thread.

property promise

Alias for field number 0

property method

Alias for field number 1

property args

Alias for field number 2

property kwargs

Alias for field number 3

class mode.threads.WorkerThread(service: mode.threads.ServiceThread, **kwargs: Any)

Thread class used for services running in a dedicated thread.

service: 'ServiceThread' = None
is_stopped: threading.Event = None
run() → None

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

stop() → None
class mode.threads.ServiceThread(*, executor: Any = None, loop: asyncio.events.AbstractEventLoop = None, thread_loop: asyncio.events.AbstractEventLoop = None, Worker: Type[mode.threads.WorkerThread] = None, **kwargs: Any)

Service subclass running within a dedicated thread.

abstract = False
wait_for_shutdown = True
wait_for_thread: bool = True

Set this to False if s.start() should not wait for the underlying thread to be fully started.

last_wakeup_at: float = 0.0
Worker

alias of WorkerThread

async on_thread_started() → None
async on_thread_stop() → None
async maybe_start() → bool

Start the service, if it has not already been started.

async start() → None
async crash(exc: BaseException) → None

Crash the service and all child services.

async stop() → None

Stop the service.

set_shutdown() → None

Set the shutdown signal.

Notes

If wait_for_shutdown is set, stopping the service will wait for this flag to be set.

on_crash(msg: str, *fmt: Any, **kwargs: Any) → None
logger = <Logger mode.threads (WARNING)>
class mode.threads.QueueServiceThread(*, executor: Any = None, loop: asyncio.events.AbstractEventLoop = None, thread_loop: asyncio.events.AbstractEventLoop = None, Worker: Type[mode.threads.WorkerThread] = None, **kwargs: Any)

Service running in separate thread.

Uses a queue to run functions inside the thread, so you can delegate calls.

logger = <Logger mode.threads (WARNING)>
abstract = False
property method_queue
async on_thread_started() → None
async on_thread_stop() → None
async call_thread(fun: Callable[..., Awaitable], *args: Any, **kwargs: Any) → Any
async cast_thread(fun: Callable[..., Awaitable], *args: Any, **kwargs: Any) → None