sqlalchemy_dlock.factory module

sqlalchemy_dlock.factory.create_async_sadlock(connection_or_session, key, /, contextual_timeout=None, **kwargs)[source]

AsyncIO version of create_sadlock()

Return type:

BaseAsyncSadLock[TypeVar(KTV), TypeVar(AsyncConnectionTV, bound= Union[AsyncConnection, AsyncSession, async_scoped_session])]

Parameters:
  • connection_or_session (AsyncConnectionTV)

  • key (KTV)

  • contextual_timeout (float | int | None)

sqlalchemy_dlock.factory.create_sadlock(connection_or_session, key, /, contextual_timeout=None, **kwargs)[source]

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 (TypeVar(ConnectionTV, bound= Union[Connection, Session, scoped_session])) – Connection or Session object SQL locking functions will be invoked on it.

  • key (TypeVar(KTV)) – ID or name of the SQL locking function

  • contextual_timeout (Union[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

Return type:

BaseSadLock[TypeVar(KTV), TypeVar(ConnectionTV, bound= Union[Connection, Session, scoped_session])]

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.