Skip to content

Locking

from uwsgiconf.runtime.locking import lock

@lock()
def locked():
    """This function will be locked with default (0) lock."""
    ...

 # or

with lock(2):
    # Code under this context manager will be locked with lock 2.
    ...

Attributes

lock

lock = Lock

Convenience alias for Lock.


Classes

Lock

Lock(num: int = 0)

Locks related stuff.

Lock number 0 is always available. More locks need to be registered with .config.locking.set_basic_params(count=X) where X is the number of locks.

Note

The same lock should be released before next acquiring.

Can be used as context manager:

1
2
3
4
.. code-block:: python

    with Lock():
        do()

Can de used as a decorator:

1
2
3
4
5
.. code-block:: python

    @Lock()
    def do():
        pass

is_set

.is_set()

"Checks whether the lock is active.

ValueError For Spooler or invalid lock number


acquire

.acquire()

Sets the lock.

ValueError For Spooler or invalid lock number


release

.release()

Unlocks the lock.

ValueError For Spooler or invalid lock number