MCPcopy Create free account
hub / github.com/celery/celery / write_pid

Method write_pid

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

Source from the content-addressed store, hash-verified

222 return False
223
224 def write_pid(self):
225 pid = os.getpid()
226 content = f'{pid}\n'
227
228 pidfile_fd = os.open(self.path, PIDFILE_FLAGS, PIDFILE_MODE)
229 pidfile = os.fdopen(pidfile_fd, 'w')
230 try:
231 pidfile.write(content)
232 # flush and sync so that the re-read below works.
233 pidfile.flush()
234 try:
235 os.fsync(pidfile_fd)
236 except AttributeError: # pragma: no cover
237 pass
238 finally:
239 pidfile.close()
240
241 rfh = open(self.path)
242 try:
243 if rfh.read() != content:
244 raise LockFailed(
245 "Inconsistency: Pidfile content doesn't match at re-read")
246 finally:
247 rfh.close()
248
249
250PIDFile = 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