qudi.util.mutex

Stand-in extension of Qt’s QMutex and QRecursiveMutex classes. Derived from the ACQ4 project.

Classes

Mutex

Extends QMutex which serves as access serialization between threads.

RecursiveMutex()

Extends QRecursiveMutex which serves as access serialization between threads.

class qudi.util.mutex.Mutex[source]

Bases: PySide2.QtCore.QMutex

Extends QMutex which serves as access serialization between threads.

This class provides: * Drop-in replacement for threading.Lock * Context management (enter/exit)

__enter__()[source]

Enter context.

Returns:
Mutex

This mutex object itself.

__exit__(*args)[source]

Exit context.

Parameters:
*args

Context arguments (type, value, traceback) passed to the method.

acquire(blocking: bool | None = True, timeout: int | float | None = -1) bool[source]

Mimics threading.Lock.acquire() to allow this class as a drop-in replacement.

Parameters:
blockingbool, optional

If True, this method will block until the mutex is locked (up to <timeout> seconds). If False, this method will return immediately regardless of the lock status. Default is True.

timeoutfloat, optional

Timeout in seconds specifying the maximum wait time for the mutex to be able to lock. Negative numbers correspond to infinite wait time. This parameter is ignored if blocking is False. Default is -1.0.

release() None[source]

Mimics threading.Lock.release() to allow this class as a drop-in replacement.

class qudi.util.mutex.RecursiveMutex[source]

Bases: qudi.util.mutex.Mutex

Extends QRecursiveMutex which serves as access serialization between threads.

This class provides: * Drop-in replacement for threading.Lock * Context management (enter/exit)

NOTE: A recursive mutex is much more expensive than using a regular mutex. So consider refactoring your code to use a simple mutex before using this object.