sc3nb.timed_queue
Classes to run register functions at certain timepoints and run asynchronously
Module Contents
Class List
Stores a timestamp, function and arguments for that function. |
|
Accumulates events as timestamps and functions. |
|
Timed queue with OSC communication. |
Content
- class sc3nb.timed_queue.Event(timestamp: float, function: Callable[Ellipsis, None], args: Iterable[Any], spawn: bool = False)[source]
Stores a timestamp, function and arguments for that function. Long running functions can be wrapped inside an own thread
- Parameters:
- timestampfloat
Time event should be executed
- functionCallable[…, None]
Function to be executed
- argsIterable[Any]
Arguments for function
- spawnbool, optional
if True, create new thread for function, by default False
Overview:
Executes function
Return self==value.
Return self<value.
Return self<=value.
Return repr(self).
- class sc3nb.timed_queue.TimedQueue(relative_time: bool = False, thread_sleep_time: float = 0.001, drop_time_threshold: float = 0.5)[source]
Accumulates events as timestamps and functions.
Executes given functions according to the timestamps
- Parameters:
- relative_timebool, optional
If True, use relative time, by default False
- thread_sleep_timefloat, optional
Sleep time in seconds for worker thread, by default 0.001
- drop_time_thresholdfloat, optional
Threshold for execution time of events in seconds. If this is exceeded the event will be dropped, by default 0.5
Overview:
Closes event processing without waiting for pending events
Closes event processing after waiting for pending events
Blocks until all pending events have completed
Adds event to queue
Get latest event from queue and remove event
Look up latest event from queue
Checks if queue is empty
Removes latest event from queue
Worker function to process events
Return repr(self).
Add time delta to the current queue time.
- put(timestamp: float, function: Callable[Ellipsis, None], args: Iterable[Any] = (), spawn: bool = False) None [source]
Adds event to queue
- Parameters:
- timestampfloat
Time (POSIX) when event should be executed
- functionCallable[…, None]
Function to be executed
- argsIterable[Any], optional
Arguments to be passed to function, by default ()
- spawnbool, optional
if True, create new sub-thread for function, by default False
- Raises:
- TypeError
raised if function is not callable
- __worker(sleep_time: float, close_event: threading.Event) NoReturn [source]
Worker function to process events
- class sc3nb.timed_queue.TimedQueueSC(server: sc3nb.osc.osc_communication.OSCCommunication = None, relative_time: bool = False, thread_sleep_time: float = 0.001)[source]
Bases:
TimedQueue
Timed queue with OSC communication.
- Parameters:
- serverOSCCommunication, optional
OSC server to handle the bundlers and messsages, by default None
- relative_timebool, optional
If True, use relative time, by default False
- thread_sleep_timefloat, optional
Sleep time in seconds for worker thread, by default 0.001
Overview:
Add a Bundler to queue
Add a message to queue
- put_bundler(onset: float, bundler: sc3nb.osc.osc_communication.Bundler) None [source]
Add a Bundler to queue
- Parameters:
- onsetfloat
Sending timetag of the Bundler
- bundlerBundler
Bundler that will be sent
- put_msg(onset: float, msg: Union[sc3nb.osc.osc_communication.OSCMessage, str], msg_params: Iterable[Any]) None [source]
Add a message to queue
- Parameters:
- onsetfloat
Sending timetag of the message
- msgUnion[OSCMessage, str]
OSCMessage or OSC address
- msg_paramsIterable[Any]
If msg is str, this will be the parameters of the created OSCMessage