|
string | addr = lambda self: '%d@%s' % (self.pid, self.host) |
|
string | fddr = lambda self: '<%s %s>' % (self.path, self.addr()) |
|
string | pddr = lambda self, lock: '<%s %s@%s>' %\ |
|
Class to handle creating and removing lockfiles
Definition at line 14 of file SingleAppInstance.py.
◆ __init__()
def python.SingleAppInstance.SingleAppInstance.__init__ |
( |
|
self, |
|
|
|
path, |
|
|
|
debug = None , |
|
|
|
blocking = False |
|
) |
| |
Definition at line 28 of file SingleAppInstance.py.
28 def __init__(self, path, debug=None, blocking = False):
29 self.pid = os.getpid()
30 self.host = socket.gethostname()
35 self.blocking = blocking
◆ __del__()
def python.SingleAppInstance.SingleAppInstance.__del__ |
( |
|
self | ) |
|
Magic method to clean up lock when program exits
Definition at line 120 of file SingleAppInstance.py.
121 '''Magic method to clean up lock when program exits'''
◆ __enter__()
def python.SingleAppInstance.SingleAppInstance.__enter__ |
( |
|
self | ) |
|
◆ __exit__()
def python.SingleAppInstance.SingleAppInstance.__exit__ |
( |
|
self, |
|
|
|
typ, |
|
|
|
value, |
|
|
|
tb |
|
) |
| |
◆ _readlock()
def python.SingleAppInstance.SingleAppInstance._readlock |
( |
|
self | ) |
|
|
private |
Internal method to read lock info
Definition at line 100 of file SingleAppInstance.py.
101 '''Internal method to read lock info'''
105 data = fh.read().rstrip().
split(
'@')
107 lock[
'pid'], lock[
'host'] = data
110 return {
'pid': 8**10,
'host':
''}
◆ acquire()
def python.SingleAppInstance.SingleAppInstance.acquire |
( |
|
self | ) |
|
Acquire a lock, returning self if successful, False otherwise
Definition at line 37 of file SingleAppInstance.py.
38 '''Acquire a lock, returning self if successful, False otherwise'''
41 lock = self._readlock()
42 print(
'Previous lock detected: %s' % self.pddr(lock))
45 fd = os.open(self.path, os.O_RDWR | os.O_CREAT, 0o777)
46 fh = os.fdopen(fd,
'r+')
50 fcntlflag = fcntl.LOCK_EX
52 fcntlflag |= fcntl.LOCK_NB
53 fcntl.lockf(fh, fcntlflag)
56 print(
'Unable to acquire lock on %s: existing lock %s' % (self.path, fh.read()))
64 modtime = os.stat(self.path)
65 outstring =
'Acquired lock: '+ self.fddr() +
' at time '+ time.ctime(modtime.st_mtime)
67 except Exception
as e:
68 if os.path.isfile(self.path):
75 raise self.FileLockAcquisitionError(
76 'Error acquiring lock: %s, reason %s' % (self.fddr(), e))
◆ islocked()
def python.SingleAppInstance.SingleAppInstance.islocked |
( |
|
self | ) |
|
Check if we already have a lock
Definition at line 112 of file SingleAppInstance.py.
113 '''Check if we already have a lock'''
◆ ownlock()
def python.SingleAppInstance.SingleAppInstance.ownlock |
( |
|
self | ) |
|
◆ release()
def python.SingleAppInstance.SingleAppInstance.release |
( |
|
self | ) |
|
Release lock, returning self
Definition at line 79 of file SingleAppInstance.py.
80 '''Release lock, returning self'''
84 fcntl.lockf(fh, fcntl.LOCK_UN)
92 outstring =
'Released lock: ' + self.fddr() +
' at time ' + time.ctime()
94 except Exception
as e:
96 raise self.FileLockReleaseError(
97 'Error releasing lock: %s, reason %s' % (self.fddr(), e))
◆ addr
string python.SingleAppInstance.SingleAppInstance.addr = lambda self: '%d@%s' % (self.pid, self.host) |
|
static |
◆ blocking
python.SingleAppInstance.SingleAppInstance.blocking |
◆ debug
python.SingleAppInstance.SingleAppInstance.debug |
◆ fddr
string python.SingleAppInstance.SingleAppInstance.fddr = lambda self: '<%s %s>' % (self.path, self.addr()) |
|
static |
◆ host
python.SingleAppInstance.SingleAppInstance.host |
◆ locked
python.SingleAppInstance.SingleAppInstance.locked |
◆ lockfile
python.SingleAppInstance.SingleAppInstance.lockfile |
◆ path
python.SingleAppInstance.SingleAppInstance.path |
◆ pddr
string python.SingleAppInstance.SingleAppInstance.pddr = lambda self, lock: '<%s %s@%s>' %\ |
|
static |
◆ pid
python.SingleAppInstance.SingleAppInstance.pid |
The documentation for this class was generated from the following file: