Skip to content

zzlib.mixin module

zzlib.mixin

zzlib.mixin.SentinelStop

Bases: BaseException

Indicates that the thread is being terminated.

zzlib.mixin.StopableMixin

Used to represent a class that can be stopped.

is_stopped()

Check if the stop event is set.

stop()

Set the stop event to signal stopping.

zzlib.mixin.ThreadingMixin

Used to enable the class to supervise one or more threads.

Group of threads will will be supervised by sessions, indicating that a task is using the threads. When the session is ended, the group of threads will be notified or forced to end. It is also possible to notify or force all sessions to end.

Warning

This class only supports CPython.

add_slave(sid, t)

Bring a single thread under supervision and give it a session id.

join()

Wait for all supervised threads to exit.

session(*args, **kw)

Starting a session, which will cause a group of Threads to be run, which will be notified or forced to end when the session is exited. Other parameters are passed to _session().

shared_session(*args, **kw)

Starts a session, which causes a group of Threads to be run, which will be prompted or forced to end when all code blocks using shared_session() have been exited.

start(*args, sid=None, **kw)

Start predefined threads as a new session.

You need to override the _session() generator to define the threads that need to be started. This generator must yield several started Thread. Other parameters are passed to _session().

stop(sid=None)

Try to stop a session.

In fact, a SentinelStop will be raised in the thread function, and you can catch the error to achieve a graceful exit.

Parameters:

Name Type Description Default
sid int

Session id, defaults to all sessions.

None