pymap.concurrent
¶
Implements some concurrency utilities used by pymap. Each has
an implementation using asyncio
and threading
concurrency
primitives.
- class pymap.concurrent.Subsystem[source]¶
Utility for creating concurrency primitives for a subsystem, either
asyncio
orthreading
.- classmethod for_executor(executor)[source]¶
Return a subsystem based on the given executor. If
executor
is None, useasyncio
. Ifexecutor
is aconcurrent.futures.ThreadPoolExecutor
, usethreading
.- Parameters:
executor (Executor | None) – The executor in use, if any.
- Return type:
- classmethod for_threading(executor)[source]¶
Return a subsystem for
threading
.- Parameters:
executor (ThreadPoolExecutor)
- Return type:
- abstract execute(future)[source]¶
Executes the future and returns its result in the subsystem. For
asyncio
, this simply meansreturn await future
. Forthreading
, it usesrun_in_executor()
to run the future in another thread.
- class pymap.concurrent.Event[source]¶
Concurrent event, one thread signals and any waiting event is released.
- abstract property subsystem: str¶
The subsystem the event was created for,
'asyncio'
or'threading'
.
- class pymap.concurrent.ReadWriteLock[source]¶
Read-write lock.
- abstract property subsystem: str¶
The subsystem the read-write lock was created for,
'asyncio'
or'threading'
.
- abstract read_lock()[source]¶
Acquires a read-lock, blocking until any write-locks are released.
- Return type:
- class pymap.concurrent.FileLock(path, expiration=600.0, read_retry_delay=(0.01, 0.03, 0.06, 0.1, 0.15, 0.25, 0.4, 0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), write_retry_delay=(0.01, 0.03, 0.06, 0.1, 0.15, 0.25, 0.4, 0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0))[source]¶
Uses the presence or absence of a file on the filesystem to simulate a read-write lock. If the file is present, other read- and write-locks will block until the file is gone. If the file is absent, read-locks will not block. Write-locks will create the file on acquire and remove it on release.
The delay arguments are a sequence of floats used as the duration of successive
sleep()
calls. If this sequence is exhausted before a lock is established,TimeoutError
is thrown.- Parameters:
- read_lock()[source]¶
Acquires a read-lock, blocking until any write-locks are released.
- Return type:
AsyncIterator[None]
- write_lock()[source]¶
Acquires a write-lock, blocking until all read- or write-locks are released.
- Return type:
AsyncIterator[None]
- class pymap.concurrent.EventT¶
Type variable with an upper bound of
Event
.alias of TypeVar(‘EventT’, bound=
Event
)
- class pymap.concurrent.RetT¶
Type variable for any return type.
alias of TypeVar(‘RetT’)