roboglia.base.BaseThread

class BaseThread(name='THREAD', patience=1.0)[source]

Bases: object

Implements a class that wraps a processing logic that is executed in a separate thread with the ability to pause / resume or fully stop the task.

The main processing should be implemented in the run method where the subclass should make sure that it checks periodically the status (paused or stopped) and behave appropriately. The run can be flanked by the setup and teardown methods where subclasses can implement logic needed before the main processing is started or finished.

This becomes very handy for loops that normally prepare the work, then run for an indefinite time, and later are closed when the owner signals.

Parameters
  • name (str) – The name of the thread.

  • patience (float) – A duration in seconds that the main thread will wait for the background thread to finish setup activities and indicate that it is in started mode.

__init__(name='THREAD', patience=1.0)[source]

Initialize self. See help(type(self)) for accurate signature.

property name

Returns the name of the thread.

setup()[source]

Thread preparation before running. Subclasses should override

run()[source]

Run method of the thread.

teardown()[source]

Thread cleanup. Subclasses should override.

property started

Indicates if the thread was started.

property stopped

Indicates if the thread was stopped.

property running

Indicates if the thread is running.

property paused

Indicates the thread was paused.

start(wait=True)[source]

Starts the task in it’s own thread.

stop(wait=True)[source]

Sends the stopping signal to the thread. By default waits for the thread to finish.

pause()[source]

Requests the thread to pause.

resume()[source]

Requests the thread to resume.