pylablib.core.mthread package¶
Submodules¶
pylablib.core.mthread.controller module¶
-
class
pylablib.core.mthread.controller.
IThreadController
(name=None)[source]¶ Bases:
object
Generic thread controller.
Deals with correctly initializing and destroying the message queue, processing standard messages, and synchronizing with other threads.
Parameters: name (str) – thread name (can be used to, e.g., get the controller from a different thread). -
process_interrupt
(msg)[source]¶ Process interrupt message (automatically called for all messages with tag starting with
"interrupt"
).Automatically called by the controller; to be overridden in subclasses.
-
process_message
(_)[source]¶ Instant message processing.
If return value is
True
, the message is assumed to be processed internally (i.e., it doesn’t get explicitly received).Automatically called by the controller; to be overridden in subclasses.
-
exhaust_messages
(tags=None, filt=None)[source]¶ Read and return (instantaneously) all available messages which satisfy the filter filt.
Called from the controlled thread.
-
wait_for_message
(tags=None, timeout=None, filt=None, exhaust=False, discard_on_timeout=False)[source]¶ Wait for a message with given tags and satisfying the filter filt.
if exhaust is
True
, returns list of all messages satisfying filt, if several of them are available immediately. if discard_on_timeout isTrue
and the wait timed out, mark the message for discarding using filt (seetag_queue.TaggedQueue.get()
).Called from the controlled thread.
-
check_interrupt
()[source]¶ Check for interrupt messages.
Useful to insert in the middle of computationally-heavy code with no synchronization, to respond to interrupts from other threads (e.g., stopping requests).
Called from the controlled thread.
-
run
()[source]¶ Body of the thread.
Automatically called by the controller; to be overridden in subclasses.
-
finalize
()[source]¶ Finalize the thread execution (regardless of the stopping reason).
Automatically called by the controller; to be overridden in subclasses.
-
add_message
(msg, sync=True, on_broken='error')[source]¶ Add the message to the queue.
If sync is
True
, do the synchronization (wait for receiving and scheduling) after sending the message. on_broken decides what happens if thethread is stopped or hasn’t started yet (seethreadprop.on_error()
).Called from any thread.
-
add_new_message
(tag, value=None, priority=0, schedule_sync='wait', receive_sync='none', sync=True, timeout=None, on_broken='error')[source]¶ Create a new message, add it to the thread’s queue, and return it.
If sync is
True
, do the synchronization (wait for receiving and scheduling) after sending the message. on_broken decides what happens if thethread is stopped or hasn’t started yet (seethreadprop.on_error()
).Called from any thread.
-
send_message
(tag, value=None, priority=0, schedule_sync='wait', receive_sync='none', sync=True, timeout=None, on_broken='error')¶ Create a new message, add it to the thread’s queue, and return it.
If sync is
True
, do the synchronization (wait for receiving and scheduling) after sending the message. on_broken decides what happens if thethread is stopped or hasn’t started yet (seethreadprop.on_error()
).Called from any thread.
-
start
(as_dependent=False, as_daemon=False)[source]¶ Start the controller.
if as_dependent is
True
, the new thread becomes dependent on the caller thread (it stops when the caller thread stops). if as_deamon isTrue
, the new thread becomes a daemon (if only daemon threads are running, they get stopped).
-
start_continuing
(stop_after_run=True)[source]¶ Start the current controller in the current non-controlled thread.
If stop_after_run is
True
, the controller is stopped after therun()
function is done; otherwise, th controller continues (e.g.,run()
can be empty, which means that this function simply initializes the controller).
-
interrupt
(subclass, value, sync=True, priority=0, timeout=None, on_broken='error')[source]¶ Send an interrupt with the given subclass and value.
If sync is
True
, wait until the interrupt is received (with the given timeout). on_broken decides what happens if thethread is stopped or hasn’t started yet (seethreadprop.on_error()
).Called from any thread.
-
call_from_thread
(func, args=None, kwargs=None, sync_recv=True, sync_done=False, as_interrupt=False, priority=0, on_broken='error')[source]¶ Call a function func with the arguments (args and kwargs) in in this controller thread.
Called from any thread.
-
stop
(sync=True)[source]¶ Stop the thread.
If called from the current thread, stop self. If called from a different thread, send a stop interrupt. In this case, if sync is
True
, wait until the thread received the message.
-
sync
(point='interrupt', timeout=None, on_broken='error')[source]¶ Synchronize with the thread.
point determines where the synchronization happens. Can be either
"interrupt"
(sync on any interrupt),"start"
(synchronize with the thread after its start), or"stop"
(synchronize with the thread after its stop).Called from a non-controlled thread.
-
add_dependent_thread
(dependent=None)[source]¶ Add a dependent thread (caller’s thread by default) to this controller.
A dependent thread is automatically stopped after this thread is stopped.
Called from a non-controlled thread.
-
set_as_dependent
()[source]¶ Set this thread as a dependent for the caller thread.
A dependent thread is automatically stopped after the caller thread is stopped.
Called from a non-controlled thread.
-
current_stage
()[source]¶ Return current stage of the process.
- Can have following values:
"created"
: thread is created, but not started"starting"
: thread is starting, but is not running yet (notifying waiting threads)"running"
: thread is executing its run code"stopping"
: thread has done running and is currently stopping (notifying waiting threads, cleaning up dependent threads and daemons)"cleaning"
: cleaning the message queue; communication is impossible at this point"broken"
: thread is finished executing
Called from any thread.
-
passed_stage
(stage)[source]¶ Check if the thread passed the given stage.
For stage description, see
current_stage()
.Called from any thread.
-
-
pylablib.core.mthread.controller.
wait_for_thread_name
(name)[source]¶ Wait until a thread with the given name starts.
-
class
pylablib.core.mthread.controller.
SimpleThreadController
(name, job, cleanup=None, args=None, kwargs=None, self_as_arg=False)[source]¶ Bases:
pylablib.core.mthread.controller.IThreadController
Simple thread.
Runs a single task, with a possible cleanup after the end.
Parameters: - name (str) – thread name (can be used to, e.g., get the controller from a different thread).
- job (callable) – function to be executed in the thread.
- cleanup (callable) – if not
None
, function to be called when the thread is stopped (regardless of the stopping reason). - args (list) – arguments for job and cleanup functions.
- kwargs (dict) – keyword arguments for job and cleanup functions.
- self_as_arg (bool) – if
True
, pass this controller as a first argument to the job and cleanup functions.
-
class
pylablib.core.mthread.controller.
ServiceThreadController
(name, reply, setup=None, cleanup=None, args=None, kwargs=None, stopped_recipient_action='ignore')[source]¶ Bases:
pylablib.core.mthread.controller.IThreadController
Service thread.
Receives and processes messages, and replies using a
reply
function.Parameters: - name (str) – thread name (can be used to, e.g., get the controller from a different thread).
- reply (callable) – message processing function; if it returns a tuple, interpret it as tag and value for a reply message.
- setup (callable) – if not
None
, function to be called when the thread is starting. - cleanup (callable) – if not
None
, function to be called when the thread is stopped (regardless of the stopping reason). - args (list) – arguments for reply, startup and cleanup functions.
- kwargs (dict) – keyword arguments for reply, startup and cleanup functions.
- stopped_recipient_action (str) – action to take if the reply recipient has stopped;
can be
"error"
(raise an error),"stop"
(stop the thread; similar to th previous) or"ignore"
(ignore and continue).
-
class
pylablib.core.mthread.controller.
RepeatingThreadController
(name, job, delay=0, setup=None, cleanup=None, args=None, kwargs=None, self_as_arg=False)[source]¶ Bases:
pylablib.core.mthread.controller.IThreadController
Recurring task thread.
Periodically repeats a single function.
Parameters: - name (str) – thread name (can be used to, e.g., get the controller from a different thread).
- job (callable) – periodically called function.
- delay (float) – calling period.
- setup (callable) – if not
None
, function to be called when the thread is starting. - cleanup (callable) – if not
None
, function to be called when the thread is stopped (regardless of the stopping reason). - args (list) – arguments for job, startup and cleanup functions.
- kwargs (dict) – keyword arguments for job, startup and cleanup functions.
- self_as_arg (bool) – if
True
, pass this controller as a first argument to the job and cleanup functions.
-
process_message
(msg)[source]¶ Instant message processing.
If return value is
True
, the message is assumed to be processed internally (i.e., it doesn’t get explicitly received).Automatically called by the controller; to be overridden in subclasses.
-
run
()[source]¶ Body of the thread.
Automatically called by the controller; to be overridden in subclasses.
-
finalize
()[source]¶ Finalize the thread execution (regardless of the stopping reason).
Automatically called by the controller; to be overridden in subclasses.
-
control
(value, sync=True, priority=0)[source]¶ Send a control signal to the thread.
If sync is
True
, wait until the signal is received before continuing.Called from a non-controlled thread.
-
trigger
(sync=True)[source]¶ Trigger an execution cycle immediately (without waiting for the required delay).
The execution is only performed if the thread is not paused.
-
sync
(point='waiting')[source]¶ Synchronize with the thread.
point determines where the synchronization happens. Can be either
"interrupt"
(sync on any interrupt),"start"
(synchronize with the thread after its start), or"stop"
(synchronize with the thread after its stop).Called from a non-controlled thread.
-
start
(as_dependent=False, as_daemon=False, paused=False, skip_first=None)[source]¶ Start the thread.
if as_dependent is
True
, the new thread becomes dependent on the caller thread (it stops when the caller thread stops). if as_deamon isTrue
, the new thread becomes a daemon (if only daemon threads are running, they get stopped). If paused isTrue
, the thread starts in a paused state (but it will still execute the first cycle, unless skip_first isTrue
). If skip_first isTrue
, skip the first cycle execution (by defaultTrue
ifpaused==True
andFalse
otherwise).
-
class
pylablib.core.mthread.controller.
MultiRepeatingThreadController
(name, setup=None, cleanup=None, args=None, kwargs=None, self_as_arg=False)[source]¶
-
class
pylablib.core.mthread.controller.
TimerThreadController
(period, callback, setup=None, cleanup=None, name=None)[source]¶ Bases:
pylablib.core.mthread.controller.RepeatingThreadController
Timer thread.
Simplified version of the
RepeatingThreadController
. Doesn’t require a name, starts as a dependent and a daemon by default.Parameters: - period (float) – calling period.
- callback (callable) – periodically called function.
- setup (callable) – if not
None
, function to be called when the thread is starting. - cleanup (callable) – if not
None
, function to be called when the thread is stopped (regardless of the stopping reason). - name (str) – thread name (can be used to, e.g., get the controller from a different thread). By default, a unique identifier.
-
start
(as_dependent=True, as_daemon=True, skip_first=None, single=False)[source]¶ Start the thread.
if as_dependent is
True
, the new thread becomes dependent on the caller thread (it stops when the caller thread stops). if as_deamon isTrue
, the new thread becomes a daemon (if only daemon threads are running, they get stopped). If skip_first isTrue
, skip the first cycle execution. If single isTrue
, start in a single mode (only execute once). In combination withskip_first=True
, performs one callback function call after the period delay.
-
pylablib.core.mthread.controller.
timer_message_notifier
(period, tag='timer', listener=None, queue_limit=None, name=None)[source]¶ Build a timer notifier thread.
This thread (
TimerThreadController
) sends notification messages to a listener thread (caller thread by default) with a given period. tag specifies the message tag. If queue_limit is notNone
, sets the limit to how many notification messages can be in the queue at a given time.
pylablib.core.mthread.message module¶
-
class
pylablib.core.mthread.message.
CallNotifier
(wait=None, notify=None, skippable=False)[source]¶ Bases:
pylablib.core.mthread.notifier.ISkippableNotifier
Wrapper for
notifier.ISkippableNotifier
, with external functions provided for_do_wait
and_do_notify
methods.Parameters: - wait (callable) – function to be called for waiting; if
None
, nothing is called. - notify (callable) – function to be called for notifying; if
None
, nothing is called. - skippable (bool) – if
True
, allows for skippable wait events (ifnotifier.ISkippableNotifier.notify()
is called beforenotifier.ISkippableNotifier.wait()
, neither methods are actually called).
- wait (callable) – function to be called for waiting; if
-
pylablib.core.mthread.message.
build_notifier
(note_tag, note_value, sync, notification_controller)[source]¶ Build a notifier object.
- sync can be:
a callable object, in which case it is called as a notifier (waiting is absent);
- a tuple
(note_tag, note_value)
, in which case it is interpreted as a"message"
notifier with the corresponding tags (see below), while the note_tag and note_value arguments are ignored;
- a tuple
- a string, in which case it determines a synchronization primitive type. Possible types are:
"none"
: ‘dummy’ synchronizer (no waiting, return immediately);"wait_event"
: standard wait-notify pattern (wait() call waits until the notify() is called from a different thread).- Waiting is implemented using the standard python threading.Event primitive (completely synchronous, can’t be interrupted; should be used carefully);
"wait"
: standard wait-notify pattern (wait() call waits until the notify() is called from a different thread).- Waiting is implemented using the thread message queue; (synchronous, but still responds to interrupts);
"message"
: send notifying message, but don’t do any waiting (asynchronous)
note_tag and note_value arguments are used for
"wait"
and"message"
synchronizers
notification_controller is a thread controller for the thread to be waiting/notified using this primitive. If it’s a no_thread_controller, sync types are coerced:
"wait"
is interpreted as"wait_even"
, and"message"
is interpreted as"none"
.
-
class
pylablib.core.mthread.message.
Message
(tag='', value=None, priority=0, sender=None, schedule_sync=None, receive_sync=None)[source]¶ Bases:
object
A message object.
Parameters: - tags (str) – message tag (used for control in the message queue).
- value – message value (if appropriate).
- priority (int) – message priority (standard is 0).
- sender – sender controller.
- schedule_sync (CallNotifier) – object which is notified when the message is scheduled (
None
means no notifier). - receive_sync (CallNotifier) – object which is notified when the message is received (
None
means no notifier).
pylablib.core.mthread.message_queue module¶
-
class
pylablib.core.mthread.message_queue.
MessageQueue
(owner)[source]¶ Bases:
object
Mostly a wrapper around
tag_queue.TaggedQueue
, with several routines specifically for dealing with messages.Parameters: owner – owner thread controller. -
static
build_notifier
(uid, sync, event_type, notification_controller)[source]¶ Create a notifier for a message with an ID uid.
If sync is a tuple
(tag, value)
, it specifies the notifier message parameters (seemessage.build_notifier()
). Otherwise, they are determined by the uid.Called from the sender thread.
-
static
build_message
(tag, value=None, priority=0, schedule_sync='wait', receive_sync='none', sender=None)[source]¶ Create a message.
tag and value determine the message contents, priority is its priority for scheduling. schedule_sync and receive_sync specify synchronizers for scheduling and receiving this message (see
message.build_notifier()
). sender is the sender thread controller (current controller by default).Called from a sender thread.
-
add_message
(msg, sync=True)[source]¶ Add the message to the queue.
If sync is
True
, do the synchronization (wait for receiving and scheduling) after sending the message.Called from a sender thread.
-
exhaust_messages
(filt, interrupt_check)[source]¶ Read and return (instantaneously) all available messages which satisfy the filter filt.
interrupt_check is an interrupt filter function, which pre-processes the message and return
True
if it was an interrupt (in which case it’s omitted in the output).Called from the receiver thread.
-
wait_for_message
(filt, interrupt_check, timeout=None, exhaust=False, discard_on_timeout=False, discard_filt=None)[source]¶ Wait for a message satisfying the filter filt.
interrupt_check is an interrupt filter function, which pre-processes the message and return
True
if it was an interrupt (in which case the waiting continues). if exhaust isTrue
, returns list of all messages satisfying filt, if several of them are available immediately. if discard_on_timeout isTrue
and the wait timed out, mark the message for discarding using discard_filt (seetag_queue.TaggedQueue.get()
).Called from the receiver thread.
-
static
-
pylablib.core.mthread.message_queue.
send_message
(dest, tag, value=None, priority=0, schedule_sync='wait', receive_sync='none', sync=True, on_broken='error')[source]¶ Send a message to the thread dest from the current thread.
-
pylablib.core.mthread.message_queue.
exhaust_messages
(tags=None, filt=None)[source]¶ Exhaust messages for the current thread.
pylablib.core.mthread.notifier module¶
-
class
pylablib.core.mthread.notifier.
ISkippableNotifier
(skippable=False)[source]¶ Bases:
object
Generic skippable notifier.
The main methods are
wait()
(wait until the event happend) andnotify()
(notify that the event happend). Only calls underlying waiting and notifying methods once, duplicate calls are ignored.Parameters: skippable (bool) – if True
, allows for skippable wait events (ifnotify()
is called beforewait()
, neither methods are actually called).-
wait
(*args, **kwargs)[source]¶ Wait for the notification.
Can only be called once per notifier lifetime. If the notifier allows skipping, and this method is called after
notify()
, return immediately.
-
pylablib.core.mthread.sync_primitives module¶
-
class
pylablib.core.mthread.sync_primitives.
ValueSynchronizer
(sync=True, note=None, receiver=None)[source]¶ Bases:
pylablib.core.mthread.notifier.ISkippableNotifier
-
wait
(timeout=None)[source]¶ Wait for the notification.
Can only be called once per notifier lifetime. If the notifier allows skipping, and this method is called after
notify()
, return immediately.
-
-
class
pylablib.core.mthread.sync_primitives.
SyncCall
(func, args=None, kwargs=None, sync=True, note=None)[source]¶ Bases:
object
-
class
pylablib.core.mthread.sync_primitives.
BasicSynchronizer
(receiver=None, blocking_sync=False)[source]¶ Bases:
object
-
class
pylablib.core.mthread.sync_primitives.
PendingSynchronizerPool
(wait_func, notify_func, blocking_sync=False, recursive_calls=False)[source]¶ Bases:
object
-
class
pylablib.core.mthread.sync_primitives.
ResourceSynchronizerPool
(grab_func, free_func, blocking_sync=False, recursive_calls=False)[source]¶ Bases:
object
-
class
pylablib.core.mthread.sync_primitives.
Lock
(blocking_sync=False)[source]¶ Bases:
pylablib.core.mthread.sync_primitives.IResourceSyncObject
-
class
pylablib.core.mthread.sync_primitives.
RLock
(blocking_sync=False)[source]¶ Bases:
pylablib.core.mthread.sync_primitives.IResourceSyncObject
-
class
pylablib.core.mthread.sync_primitives.
Semaphore
(value, upper_bound=None, blocking_sync=False)[source]¶ Bases:
pylablib.core.mthread.sync_primitives.IResourceSyncObject
-
class
pylablib.core.mthread.sync_primitives.
Event
(flag=False, blocking_sync=False)[source]¶ Bases:
object
-
class
pylablib.core.mthread.sync_primitives.
VersionEvent
(blocking_sync=False)[source]¶ Bases:
object
-
exception
pylablib.core.mthread.sync_primitives.
BrokenBarrierError
(msg=None)[source]¶ Bases:
Exception
-
class
pylablib.core.mthread.sync_primitives.
Barrier
(parties, blocking_sync=None)[source]¶ Bases:
object
-
class
pylablib.core.mthread.sync_primitives.
Queue
(max_size=None, blocking_sync=False)[source]¶ Bases:
object
-
class
pylablib.core.mthread.sync_primitives.
ThreadObserverPool
(expand_tuple=True)[source]¶ Bases:
pylablib.core.utils.observer_pool.ObserverPool
-
add_observer
(callback, name=None, filt=None, priority=0, attr=None, cacheable=False)[source]¶ Add the observer callback.
Same as
observer_pool.ObserverPool.add_observer()
, but callback can be a string, in which case it’s interpreted as sending a message to a thread with the given name.
-
pylablib.core.mthread.tag_queue module¶
Tagged queue with priority and size limitation (set tag-wise).
-
exception
pylablib.core.mthread.tag_queue.
BrokenQueueError
(msg=None)[source]¶ Bases:
RuntimeError
An error signalizing that the queue is in a broken (shut down) state.
-
class
pylablib.core.mthread.tag_queue.
TaggedQueue
[source]¶ Bases:
object
Tagged queue with priority and size limitation (set tag-wise).
Supports multi-thread adding, but only single-thread extracting (receiving function is completely synchronous). Item is assumed to have
tag
andpriority
properties, andscheduled()
andreceived()
methods (callbacks).Extraction and discarding is based on filter functions. These should be as simple as possible and have short determined runtime (no synchronization or locks) to prevent deadlocks. When item is scheduled (i.e., added and passes length limitation),
item.scheduled()
method is called; when item is extracted,item.received()
method is called; under various circumstances, both of these methods may be called in either adding thread, or extracting thread. It is guaranteed thatscheduled()
is called beforereceived()
, and both methods are called eventually if the message is ever extracted or discarded.-
put
(item)[source]¶ Put an item in the queue.
This function doesn’t perform synchronization waits as long as
scheduled()
andreceived()
methods of item don’t perfrom them.
-
get
(filt=None, timeout=None, discard_on_timeout=False, discard_filt=None)[source]¶ Extract an item from the queue which satisfies filt filter function.
If timeout is not
None
, it determines the wait time. If it is passed before an item has been acquired, the returnNone
. If discard_on_timeout isTrue
and timeout is passed, marks discard_filt (same as filt by default) for discarding; this means that the next time a single message satisfying discard_filt is scheduled (either directly duringput()
, or from scheduling queue duringget()
), it is silently ‘received’ (notified of scheduling and receiving, but never explicitly passed to the destination thread).
-
remove
(item, only_unscheduled=False)[source]¶ Remove the item if it is in the queue without calling its
scheduled
orreceived
methods.Return
True
if removal is successful, andFalse
otherwise. Ifonly_unscheduled==True
, only remove item if it hasn’t been scheduled yet.
-
clear
(notify_all=True, ignore_exceptions=True, mark_broken=True)[source]¶ Clear the queue.
If
notify_all==True
, behave as if all the messages are received or discarded; otherwise, just remove them silently (equivalent toremove()
method). Ifignore_exceptions==True
, ignore exceptions on scheduling and receiving (e.g., if the notified thread is stopped); the queue is cleaned regardless. Ifmark_broken==True
, mark the queue as broken (any subsequent calls to its methods raiseBrokenQueueError
).
-
-
pylablib.core.mthread.tag_queue.
build_filter
(tags=None, filt=None, uncond_tags=None, tag_separator=None)[source]¶ Build a filter function.
Parameters: - tags ([str]) – list of prefixes that match message tags.
- filt (callable) – an additional filter function which needs to be satisfied (checking, e.g., message content to decide if it should be extracted).
- uncond_tags ([str]) – works like tags, but independently of filt function (allows message even if filt returns
False
). - tag_separator (str) – a separator used to divide tag levels (usually
'.'
or'/'
). If it’s notNone
, tags are matched only either exactly, or if they’re followed by tag separator (i.e., each tag level is treated as an indivisible word).
pylablib.core.mthread.threadprop module¶
-
exception
pylablib.core.mthread.threadprop.
ThreadError
(msg=None)[source]¶ Bases:
RuntimeError
Generic thread error.
-
exception
pylablib.core.mthread.threadprop.
NotRunningThreadError
(msg=None)[source]¶ Bases:
pylablib.core.mthread.threadprop.ThreadError
Thread error for a case of a missing or stopped thread.
-
exception
pylablib.core.mthread.threadprop.
NoControllerThreadError
(msg=None)[source]¶ Bases:
pylablib.core.mthread.threadprop.ThreadError
Thread error for a case of thread having no conrollers.
-
pylablib.core.mthread.threadprop.
on_error
(action, error_object=None)[source]¶ React to an error depending on the action.
action can be
'error'
(raise error_object if it’s supplied, orThreadError
by default),'stop'
(raise an appropriate exception to stop the thread),'return_error'
(return error_object) or'ignore'
(do nothing).
-
exception
pylablib.core.mthread.threadprop.
InterruptException
(msg=None)[source]¶ Bases:
Exception
Generic interrupt exception (raised by some function to signal interrupts from other threads).
-
exception
pylablib.core.mthread.threadprop.
InterruptExceptionStop
(msg=None)[source]¶ Bases:
pylablib.core.mthread.threadprop.InterruptException
Interrupt exception denoting thread stop request.
-
class
pylablib.core.mthread.threadprop.
NoThreadController
[source]¶ Bases:
object
A ‘dummy’ thread controller implementing the most standard function for a thread without any explicitly created controller.
-
pylablib.core.mthread.threadprop.
current_controller
(require_controller=False)[source]¶ Return the controller of the current thread.
If the thread has no controller and
require_controller==False
, return aNoThreadController
object; otherwise, raiseNoControllerThreadError
.
-
pylablib.core.mthread.threadprop.
has_controller
(thread)[source]¶ Check if the current thread has a controller.
-
pylablib.core.mthread.threadprop.
all_controllers
()[source]¶ Return a list of all the available thread controllers.
-
pylablib.core.mthread.threadprop.
controller_by_name
(name, require_controller=False)[source]¶ Return a controller for a given name.
If the controller is not found and
require_controller==False
, return aNoThreadController
object; otherwise, raiseNoControllerThreadError
.
-
pylablib.core.mthread.threadprop.
as_controller
(ctrl, require_controller=False)[source]¶ Return a controller corresponding to ctrl.
ctrl can be
None
(return current thread controller), a thread name, or a thread controller instance. If the cooresponding controller doesn’t exist andrequire_controller==False
, return aNoThreadController
object; otherwise, raiseNoControllerThreadError
.
-
pylablib.core.mthread.threadprop.
current_message_queue
(require_queue=False)[source]¶ Return a message queue corresponding to the current thread.
If the queue doesn’t exist and
require_queue==False
, return aNoMessageQueue
object; otherwise, raiseNoControllerThreadError
.
-
pylablib.core.mthread.threadprop.
sleep
(delay)[source]¶ Sleep for delay seconds.
Behavior depends on whether the thread has a controller.
-
pylablib.core.mthread.threadprop.
stop
()[source]¶ Stop the current thread by raising an appropriate interrupt exception.
Behavior depends on whether the thread has a controller.