src.core.event_loop_utils module
Event loop utilities for handling asyncio locks across different contexts.
This module provides utilities to ensure asyncio locks work correctly
across different event loop contexts, particularly important for HTTP
transport where each request might have its own event loop.
-
class src.core.event_loop_utils.EventLoopLockManager[source]
Bases: object
Manages asyncio locks across different event loops.
This class ensures that locks are created in the correct event loop
context, preventing “bound to a different event loop” errors.
-
__init__()[source]
Initialize the lock manager.
- Return type:
None
-
get_lock()[source]
Get or create a lock for the current event loop.
- Returns:
A lock bound to the current event loop
- Return type:
Lock
-
clear()[source]
Clear all locks (useful for testing).
- Return type:
None
-
class src.core.event_loop_utils.ThreadLocalLockManager[source]
Bases: object
Thread-local lock manager for simpler cases.
Each thread gets its own lock, avoiding event loop binding issues.
-
__init__()[source]
Initialize the thread-local storage.
- Return type:
None
-
get_lock()[source]
Get or create a lock for the current thread.
- Returns:
A lock for the current thread
- Return type:
Lock
-
src.core.event_loop_utils.create_event_loop_safe_lock()[source]
Create a lock that’s safe to use across event loops.
This is a simple factory function that creates a new lock
in the current event loop context.
- Returns:
A new lock bound to the current event loop
- Return type:
Lock