sqlalchemy_dlock.factory module¶
- sqlalchemy_dlock.factory.create_sadlock(connection_or_session: Connection | Session | scoped_session, key, /, contextual_timeout: float | int | None = None, **kwargs) BaseSadLock[source]¶
Create a database distributed lock object
All arguments will be passed to a sub-class of
BaseSadLock, depend on the type ofconnection_session’s SQLAlchemy engine.- Parameters:
connection_or_session (Connection | Session | scoped_session) – Connection or Session object SQL locking functions will be invoked on it.
key – ID or name of the SQL locking function
contextual_timeout (float | int | None) –
Timeout(seconds) for Context Managers.
When called in a
withstatement, the new created lock object will pass it totimeoutargument ofBaseSadLock.acquire().A
TimeoutErrorwill be thrown if can not acquire aftercontextual_timeout
- Returns:
New created lock object
Type of the lock object is a sub-class of
BaseSadLock, which depends on the passed-in SQLAlchemy connection or session.MySQL and PostgreSQL connection/session are supported til now.
- Return type: