sqlalchemy_dlock.factory module#

sqlalchemy_dlock.factory.create_sadlock(connection_or_session: TConnectionOrSession, key, /, contextual_timeout: float | int | None = None, **kwargs) BaseSadLock#

Create a database distributed lock object

All arguments will be passed to a sub-class of BaseSadLock, depend on the type of connection_session’s SQLAlchemy engine.

Parameters:
  • connection_or_session (TConnectionOrSession) – 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 with statement, the new created lock object will pass it to timeout argument of BaseSadLock.acquire().

    A TimeoutError will be thrown if can not acquire after contextual_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:

BaseSadLock