sebdevine / ilock

Inter-process named lock library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ilock v.1.0.2

About

This is inter-process named lock library. It provides only one class ILock with very simple interface.

Based on locking unique temporary files with portalocker.

Installation

$ pip install ilock

Examples

Here's a basic example:

from ilock import ILock

with ILock('Unique lock name'):
    # The code should be run as a system-wide single instance
    ...

Example using timeout:

from ilock import ILock, ILockException

try:
    with ILock('Unique lock name', timeout=15):
        # The code should be run as a system-wide single instance
        ...
except ILockException:
    # ILockException is raised when timeout was reached, but the lock wasn't acquired
    ...

Example using reentrant lock:

from ilock import ILock, ILockException

lock = ILock('Unique lock name', reentrant=True)

def foo():
    with lock:
        # The code should be run as a system-wide single instance
        ...

with lock:
    # The code should be run as a system-wide single instance
    ...
    # Call foo() without blocking
    foo()
    ...

License

BSD

About

Inter-process named lock library

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 100.0%