nspyre.gui.threadsafe

Module Contents

Classes

QThreadSafeObject

Qt object associated with a new QThread. Implements several methods to

class nspyre.gui.threadsafe.QThreadSafeObject

Qt object associated with a new QThread. Implements several methods to make it easier to work with data in a thread-safe way.

mutex

Mutex to lock access to instance variables.

thread

Thread to manage access requests for this object.

start()

Start the internal thread to handle requests.

stop()

Quit the internal thread.

run_main(fun, *args, blocking=False, **kwargs)

Run the given function on the main thread.

Parameters:
  • fun – Function to run.

  • args – Arguments to the function.

  • kwargs – Keyword arguments to the function.

  • blocking – If true, block until the function returns. Non-blocking calls cannot return anything.

Returns:

Return value of the function.

run_safe(fun, *args, blocking=False, **kwargs)

Run a given function on the thread of this object.

Parameters:
  • fun (Callable) – Function to run.

  • args – Arguments to the function.

  • kwargs – Keyword arguments to the function.

  • blocking – If true, block until the function returns. Non-blocking calls cannot return anything.

Returns:

Return value of the function.

get_safe(attrs)

Retrieve object attributes in a thread-safe way by accessing them while holding the internal mutex.

Parameters:

attrs (list[str]) – Object attribute names.

Returns:

tuple of object attributes.

Return type:

tuple