pidlock: use fstring where aplicable

This commit is contained in:
RhodeCode Admin 2023-05-11 12:09:09 +02:00
parent 087ed92f1e
commit f58a7b94bb

View file

@ -24,7 +24,6 @@ import errno
from multiprocessing.util import Finalize
class LockHeld(Exception):
pass
@ -49,7 +48,7 @@ class DaemonLock(object):
self.desc = desc
self.debug = debug
self.held = False
#run the lock automatically !
# run the lock automatically !
self.lock()
self._finalize = Finalize(self, DaemonLock._on_finalize,
args=(self, debug), exitpriority=10)
@ -58,7 +57,7 @@ class DaemonLock(object):
def _on_finalize(lock, debug):
if lock.held:
if debug:
print('leck held finilazing and running lock.release()')
print('lock held finalazing and running lock.release()')
lock.release()
def lock(self):
@ -66,7 +65,7 @@ class DaemonLock(object):
locking function, if lock is present it
will raise LockHeld exception
"""
lockname = '%s' % (os.getpid())
lockname = f'{os.getpid()}'
if self.debug:
print('running lock')
self.trylock()
@ -85,8 +84,8 @@ class DaemonLock(object):
running_pid = -1
if self.debug:
print('lock file present running_pid: %s, '
'checking for execution' % (running_pid,))
print(f'lock file present running_pid: {running_pid}, '
f'checking for execution')
# Now we check the PID from lock file matches to the current
# process PID
if running_pid:
@ -94,15 +93,14 @@ class DaemonLock(object):
os.kill(running_pid, 0)
except OSError as exc:
if exc.errno in (errno.ESRCH, errno.EPERM):
print("Lock File is there but"
" the program is not running")
print("Removing lock file for the: %s" % running_pid)
print("Lock File is there but the program is not running")
print(f"Removing lock file for the: {running_pid}")
self.release()
else:
raise
else:
print("You already have an instance of the program running")
print("It is running as process %s" % running_pid)
print(f"It is running as process {running_pid}")
raise LockHeld()
except IOError as e:
@ -118,16 +116,16 @@ class DaemonLock(object):
if self.callbackfn:
# execute callback function on release
if self.debug:
print('executing callback function %s' % self.callbackfn)
print(f'executing callback function {self.callbackfn}')
self.callbackfn()
try:
if self.debug:
print('removing pidfile %s' % self.pidfile)
print(f'removing pidfile {self.pidfile}')
os.remove(self.pidfile)
self.held = False
except OSError as e:
if self.debug:
print('removing pidfile failed %s' % e)
print(f'removing pidfile failed {e}')
pass
def makelock(self, lockname, pidfile):
@ -138,7 +136,7 @@ class DaemonLock(object):
:param pidfile: the file to write the pid in
"""
if self.debug:
print('creating a file %s and pid: %s' % (pidfile, lockname))
print(f'creating a file {lockname} and pid: {pidfile}')
dir_, file_ = os.path.split(pidfile)
if not os.path.isdir(dir_):