|
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 13 of file SingleAppInstance.py.
◆ __init__()
def python.SingleAppInstance.SingleAppInstance.__init__ |
( |
|
self, |
|
|
|
path, |
|
|
|
debug = None , |
|
|
|
blocking = False |
|
) |
| |
Definition at line 27 of file SingleAppInstance.py.
27 def __init__(self, path, debug=None, blocking = False):
28 self.pid = os.getpid()
29 self.host = socket.gethostname()
34 self.blocking = blocking
◆ __del__()
def python.SingleAppInstance.SingleAppInstance.__del__ |
( |
|
self | ) |
|
Magic method to clean up lock when program exits
Definition at line 119 of file SingleAppInstance.py.
120 '''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 99 of file SingleAppInstance.py.
100 '''Internal method to read lock info'''
104 data = fh.read().rstrip().
split(
'@')
106 lock[
'pid'], lock[
'host'] = data
109 return {
'pid': 8**10,
'host':
''}
◆ acquire()
def python.SingleAppInstance.SingleAppInstance.acquire |
( |
|
self | ) |
|
Acquire a lock, returning self if successful, False otherwise
Definition at line 36 of file SingleAppInstance.py.
37 '''Acquire a lock, returning self if successful, False otherwise'''
40 lock = self._readlock()
41 print(
'Previous lock detected: %s' % self.pddr(lock))
44 fd = os.open(self.path, os.O_RDWR | os.O_CREAT, 0o777)
45 fh = os.fdopen(fd,
'r+')
49 fcntlflag = fcntl.LOCK_EX
51 fcntlflag |= fcntl.LOCK_NB
52 fcntl.lockf(fh, fcntlflag)
55 print(
'Unable to acquire lock on %s: existing lock %s' % (self.path, fh.read()))
63 modtime = os.stat(self.path)
64 outstring =
'Acquired lock: '+ self.fddr() +
' at time '+ time.ctime(modtime.st_mtime)
66 except Exception
as e:
67 if os.path.isfile(self.path):
74 raise self.FileLockAcquisitionError(
75 '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 111 of file SingleAppInstance.py.
112 '''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 78 of file SingleAppInstance.py.
79 '''Release lock, returning self'''
83 fcntl.lockf(fh, fcntl.LOCK_UN)
91 outstring =
'Released lock: ' + self.fddr() +
' at time ' + time.ctime()
93 except Exception
as e:
95 raise self.FileLockReleaseError(
96 '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: