The global lock

Python-LLFUSE uses a global lock to synchronize concurrent requests. Since the GIL already enforces that Python threads do not run concurrently, this does not result in any additional performance penalties. However, the use of an explicit lock allows direct control over which Python thread is running at a given time.

Request handlers will always be called with the global lock acquired. However, they may release the global lock for potentially time consuming operations (like network or disk I/O), or to give other threads a chance to run during longer computations.

Non-request handling threads may acquire the global lock to ensure that the execution of a particular code block will not be interrupted by any request handlers.

Obviously, any method that directly or indirectly releases the global lock must be prepared to be called again while it has released the lock. In addition, it (and all its callers) must not hold any prior locks, since this may lead to deadlocks when re-acquiring the global lock. For this reason it is crucial that every method that directly or indirectly releases the lock is explicitly marked as such.

The global lock is controlled with the lock and lock_released attributes of the llfuse module:

llfuse.lock_released

Controls the global lock. This object can be used as a context manager for the with statement to execute a block of code with the global lock released.

llfuse.lock

Controls the global lock. This object can be used as a context manager for the with statement to execute a block of code with the global lock acquired.

Note that this object resembles a threading.Lock instance but is an instance of the llfuse.Lock class which is quite different from threading.Lock.

The lock object has the following methods:

class llfuse.Lock
Lock.acquire()

Lock.acquire(self, timeout=None) Acquire global lock

If timeout is not None, and the lock could not be acquired after waiting for timeout seconds, return False. Otherwise return True.
Lock.release(self)

Release global lock

Lock.yield_(self, count=1)

Yield global lock to a different thread

A call to yield_ is roughly similar to:

for i in range(count):
    if no_threads_waiting_for(lock):
        break
    lock.release()
    lock.acquire()

However, when using yield_ it is guaranteed that the lock will actually be passed to a different thread (the above pseude-code may result in the same thread re-acquiring the lock count times).