Skip to content

Instantly share code, notes, and snippets.

@Kronuz
Created August 17, 2012 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kronuz/3383270 to your computer and use it in GitHub Desktop.
Save Kronuz/3383270 to your computer and use it in GitHub Desktop.
Celery 3.0 and "Stale pidfile exists. Removing it." message
--- celery/apps/beat.py
+++ celery/apps/beat.py
@@ -12,6 +12,7 @@
"""
from __future__ import absolute_import
+import atexit
import socket
import sys
@@ -77,7 +78,8 @@ class Beat(configurated):
def start_scheduler(self):
c = self.colored
if self.pidfile:
- platforms.create_pidlock(self.pidfile)
+ pidlock = platforms.create_pidlock(self.pidfile).acquire()
+ atexit.register(pidlock.release)
beat = self.Service(app=self.app,
max_interval=self.max_interval,
scheduler_cls=self.scheduler_cls,
--- celery/events/snapshot.py
+++ celery/events/snapshot.py
@@ -12,6 +12,8 @@
"""
from __future__ import absolute_import
+import atexit
+
from kombu.utils.limits import TokenBucket
from celery import platforms
@@ -90,7 +92,8 @@ def evcam(camera, freq=1.0, maxrate=None, loglevel=0,
app = app_or_default(app)
if pidfile:
- platforms.create_pidlock(pidfile)
+ pidlock = platforms.create_pidlock(pidfile).acquire()
+ atexit.register(pidlock.release)
app.log.setup_logging_subsystem(loglevel, logfile)
--- celery/platforms.py
+++ celery/platforms.py
@@ -221,8 +221,6 @@ def create_pidlock(pidfile):
pidlock = PIDFile(pidfile)
if pidlock.is_locked() and not pidlock.remove_if_stale():
raise SystemExit(PIDLOCKED % (pidfile, pidlock.read_pid()))
- pidlock.acquire()
- atexit.register(pidlock.release)
return pidlock
--- celery/worker/__init__.py
+++ celery/worker/__init__.py
@@ -341,7 +341,8 @@ class WorkController(configurated):
"""Starts the workers main loop."""
self._state = self.RUN
if self.pidfile:
- self.pidlock = platforms.create_pidlock(self.pidfile)
+ self.pidlock = platforms.create_pidlock(self.pidfile).acquire()
+ atexit.register(self.pidlock.release)
try:
for i, component in enumerate(self.components):
logger.debug('Starting %s...', qualname(component))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment