bpod_core.bpod.threads.SoftcodeThread

class bpod_core.bpod.threads.SoftcodeThread

Bases: Thread

Consumer thread that executes softcode handlers sent from the Bpod.

ReadThread feeds RawSoftcode items into queue; SoftcodeThread drains that queue and calls the registered handler for each softcode.

The handler can be swapped at any time via set_handler() without restarting the thread — the new handler takes effect on the next softcode.

Handler exceptions are caught, logged, and execution continues.

__init__(*, softcode_handler) None
Parameters:

softcode_handler (Callable[[int], None] | None)

Return type:

None

drain() None

Block until the queue is empty and any running handler has returned.

Return type:

None

run() None

Execute the SoftcodeThread.

Return type:

None

set_handler(handler) None

Set the softcode handler, taking effect on the next received softcode.

Return type:

None

Parameters:

handler (Callable[[int], None] | None)

set_time_reference(time_ref) None

Update the session clock reference used for Bpod-relative latency logging.

Return type:

None

Parameters:

time_ref (TimeReferences)

queue: SimpleQueue[RawSoftcode]

Softcode queue shared with ReadThread.