Преглед на файлове

Somehow closing the DB/cache connection was merged out.

Ask Solem преди 16 години
родител
ревизия
2c194fd273
променени са 1 файла, в които са добавени 26 реда и са изтрити 0 реда
  1. 26 0
      celery/worker/job.py

+ 26 - 0
celery/worker/job.py

@@ -1,3 +1,8 @@
+"""
+
+Jobs Executable by the Worker Server.
+
+"""
 from celery.conf import SEND_CELERY_TASK_ERROR_EMAILS
 from celery.registry import tasks
 from celery.datastructures import ExceptionInfo
@@ -56,6 +61,27 @@ def jail(task_id, task_name, func, args, kwargs):
     """
     ignore_result = getattr(func, "ignore_result", False)
     timer_stat = TaskTimerStats.start(task_id, task_name, args, kwargs)
+        
+    # See: http://groups.google.com/group/django-users/browse_thread/
+    #       thread/78200863d0c07c6d/38402e76cf3233e8?hl=en&lnk=gst&
+    #       q=multiprocessing#38402e76cf3233e8
+    from django.db import connection
+    connection.close()
+
+    # Reset cache connection only if using memcached/libmemcached
+    from django.core import cache
+    # XXX At Opera we use a custom memcached backend that uses libmemcached
+    # instead of libmemcache (cmemcache). Should find a better solution for
+    # this, but for now "memcached" should probably be unique enough of a
+    # string to not make problems.
+    cache_backend = cache.settings.CACHE_BACKEND
+    if hasattr(cache, "parse_backend_uri"):
+        cache_scheme = cache.parse_backend_uri(cache_backend)[0]
+    else:
+        # Django <= 1.0.2
+        cache_scheme = cache_backend.split(":", 1)[0]
+    if "memcached" in cache_scheme:
+        cache.cache.close()
 
     # Backend process cleanup
     default_backend.process_cleanup()