PyMySQLLock package

Submodules

PyMySQLLock.connection_factory module

class PyMySQLLock.connection_factory.ConnectionFactory(*args, **kwargs)[source]

Bases: object

ConnectionFactory creates new mysql connections (session). It tries to import one of supported mysql python connector/library and passes given arguments to that library’s connect function.

new()[source]

Creates a mysql connection with the found mysql library, passing the args and kwargs given with constructor.

Returns:A mysql connection

PyMySQLLock.lock module

class PyMySQLLock.lock.Lock(locker, name)[source]

Bases: object

Represents a lock object which has one-to-one correspondence with a Mysql connection. A lock is held by a connection.

acquire(timeout=-1, refresh_interval_secs=10)[source]

Try to obtain lock with the set name.

Parameters:
  • timeout – Timeout for getting the lock in seconds. Defaults to -1 which will wait for indefinite time.
  • refresh_interval_secs – Interval at which a thread will keep pinging on mysql connection that’s holding the lock.
Returns:

The return value is True if the lock is acquired successfully, False if not (for example if the

timeout expired).

locked()[source]

Check whether lock is acquired or not.

Returns:True if lock is acquired, False if not.
refresh(interval_seconds)[source]
release()[source]

Releases the lock and closes the corresponding mysql connection.

Returns:No return value.

PyMySQLLock.locker module

Main module.

class PyMySQLLock.locker.Locker(*args, **kwargs)[source]

Bases: object

Locker is primary interface to user with this library. Locker is used to create locks with given name.

get_all_locks()[source]

Get all locks queries mysql metadata table to get all user acquired locks.

For mysql 5.7 and older, instrumentations needs to be enabled in order for this API to work. Read more at: https://dev.mysql.com/doc/refman/5.7/en/performance-schema-metadata-locks-table.html

For mysql 8, this API will work on default setup of mysql.

Returns:list of locks acquired on the given mysql database
lock(name)[source]

Creates and returns a Lock object with given name. :param name: Name of the lock. :return: A Lock object.

lock_class

alias of PyMySQLLock.lock.Lock

Module contents