MCPcopy
hub / github.com/celery/celery / write_pid

Method write_pid

celery/platforms.py:215–238  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

213 return False
214
215 def write_pid(self):
216 pid = os.getpid()
217 content = f'{pid}\n'
218
219 pidfile_fd = os.open(self.path, PIDFILE_FLAGS, PIDFILE_MODE)
220 pidfile = os.fdopen(pidfile_fd, 'w')
221 try:
222 pidfile.write(content)
223 # flush and sync so that the re-read below works.
224 pidfile.flush()
225 try:
226 os.fsync(pidfile_fd)
227 except AttributeError: # pragma: no cover
228 pass
229 finally:
230 pidfile.close()
231
232 rfh = open(self.path)
233 try:
234 if rfh.read() != content:
235 raise LockFailed(
236 "Inconsistency: Pidfile content doesn't match at re-read")
237 finally:
238 rfh.close()
239
240
241PIDFile = Pidfile # XXX compat alias

Callers 3

test_write_pidMethod · 0.95
acquireMethod · 0.95

Calls 6

openFunction · 0.85
LockFailedClass · 0.85
openMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45

Tested by 2

test_write_pidMethod · 0.76