Skip to content

✨ feat(async): add AsyncReadWriteLock#506

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:505
Mar 1, 2026
Merged

✨ feat(async): add AsyncReadWriteLock#506
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:505

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat commented Mar 1, 2026

The library has AsyncFileLock for async file locking and ReadWriteLock for sync shared-read/exclusive-write locking, but no way to use read/write locks from async code. This was requested in #505.

Since Python's sqlite3 module has no async API, AsyncReadWriteLock wraps the existing ReadWriteLock and dispatches all blocking SQLite operations to a thread pool via loop.run_in_executor() — the same pattern already used by BaseAsyncFileLock. 🔄 The class uses composition rather than inheritance because ReadWriteLock has a fundamentally different hierarchy from BaseFileLock. All reentrancy, upgrade/downgrade, and singleton semantics are delegated to the inner ReadWriteLock instance.

The async context managers read_lock() and write_lock() mirror the sync API, and a custom executor can be passed for applications that need control over the thread pool. ✨ The Sphinx PatchedPythonDomain was extended to map internal stdlib paths (asyncio.events.AbstractEventLoop, concurrent.futures._base.Executor) to their public equivalents, which benefits any future code using these types in documented signatures.

Closes #505

Issue tox-dev#505 requests async read/write lock support. Since Python's
sqlite3 module has no async API, AsyncReadWriteLock wraps the existing
ReadWriteLock and dispatches all blocking SQLite operations to a
thread pool via loop.run_in_executor — the same pattern used by
BaseAsyncFileLock.

Closes tox-dev#505
@gaborbernat gaborbernat enabled auto-merge (squash) March 1, 2026 14:46
@gaborbernat gaborbernat merged commit df2754e into tox-dev:main Mar 1, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add async read/write file lock support

1 participant