Show More
@@ -24,7 +24,6 b' import errno' | |||
|
24 | 24 | from multiprocessing.util import Finalize |
|
25 | 25 | |
|
26 | 26 | |
|
27 | ||
|
28 | 27 | class LockHeld(Exception): |
|
29 | 28 | pass |
|
30 | 29 | |
@@ -49,7 +48,7 b' class DaemonLock(object):' | |||
|
49 | 48 | self.desc = desc |
|
50 | 49 | self.debug = debug |
|
51 | 50 | self.held = False |
|
52 | #run the lock automatically ! | |
|
51 | # run the lock automatically ! | |
|
53 | 52 | self.lock() |
|
54 | 53 | self._finalize = Finalize(self, DaemonLock._on_finalize, |
|
55 | 54 | args=(self, debug), exitpriority=10) |
@@ -58,7 +57,7 b' class DaemonLock(object):' | |||
|
58 | 57 | def _on_finalize(lock, debug): |
|
59 | 58 | if lock.held: |
|
60 | 59 | if debug: |
|
61 |
print('l |
|
|
60 | print('lock held finalazing and running lock.release()') | |
|
62 | 61 | lock.release() |
|
63 | 62 | |
|
64 | 63 | def lock(self): |
@@ -66,7 +65,7 b' class DaemonLock(object):' | |||
|
66 | 65 | locking function, if lock is present it |
|
67 | 66 | will raise LockHeld exception |
|
68 | 67 | """ |
|
69 |
lockname = ' |
|
|
68 | lockname = f'{os.getpid()}' | |
|
70 | 69 | if self.debug: |
|
71 | 70 | print('running lock') |
|
72 | 71 | self.trylock() |
@@ -85,8 +84,8 b' class DaemonLock(object):' | |||
|
85 | 84 | running_pid = -1 |
|
86 | 85 | |
|
87 | 86 | if self.debug: |
|
88 |
print('lock file present running_pid: |
|
|
89 |
'checking for execution' |
|
|
87 | print(f'lock file present running_pid: {running_pid}, ' | |
|
88 | f'checking for execution') | |
|
90 | 89 | # Now we check the PID from lock file matches to the current |
|
91 | 90 | # process PID |
|
92 | 91 | if running_pid: |
@@ -94,15 +93,14 b' class DaemonLock(object):' | |||
|
94 | 93 | os.kill(running_pid, 0) |
|
95 | 94 | except OSError as exc: |
|
96 | 95 | if exc.errno in (errno.ESRCH, errno.EPERM): |
|
97 | print("Lock File is there but" | |
|
98 |
|
|
|
99 | print("Removing lock file for the: %s" % running_pid) | |
|
96 | print("Lock File is there but the program is not running") | |
|
97 | print(f"Removing lock file for the: {running_pid}") | |
|
100 | 98 | self.release() |
|
101 | 99 | else: |
|
102 | 100 | raise |
|
103 | 101 | else: |
|
104 | 102 | print("You already have an instance of the program running") |
|
105 |
print("It is running as process |
|
|
103 | print(f"It is running as process {running_pid}") | |
|
106 | 104 | raise LockHeld() |
|
107 | 105 | |
|
108 | 106 | except IOError as e: |
@@ -118,16 +116,16 b' class DaemonLock(object):' | |||
|
118 | 116 | if self.callbackfn: |
|
119 | 117 | # execute callback function on release |
|
120 | 118 | if self.debug: |
|
121 |
print('executing callback function |
|
|
119 | print(f'executing callback function {self.callbackfn}') | |
|
122 | 120 | self.callbackfn() |
|
123 | 121 | try: |
|
124 | 122 | if self.debug: |
|
125 |
print('removing pidfile |
|
|
123 | print(f'removing pidfile {self.pidfile}') | |
|
126 | 124 | os.remove(self.pidfile) |
|
127 | 125 | self.held = False |
|
128 | 126 | except OSError as e: |
|
129 | 127 | if self.debug: |
|
130 |
print('removing pidfile failed |
|
|
128 | print(f'removing pidfile failed {e}') | |
|
131 | 129 | pass |
|
132 | 130 | |
|
133 | 131 | def makelock(self, lockname, pidfile): |
@@ -138,7 +136,7 b' class DaemonLock(object):' | |||
|
138 | 136 | :param pidfile: the file to write the pid in |
|
139 | 137 | """ |
|
140 | 138 | if self.debug: |
|
141 |
print('creating a file |
|
|
139 | print(f'creating a file {lockname} and pid: {pidfile}') | |
|
142 | 140 | |
|
143 | 141 | dir_, file_ = os.path.split(pidfile) |
|
144 | 142 | if not os.path.isdir(dir_): |
General Comments 0
You need to be logged in to leave comments.
Login now