Ticket #19117: 0001-Re-connect-database-and-memcached-after-fork.patch

File 0001-Re-connect-database-and-memcached-after-fork.patch, 2.1 KB (added by Sebastian Noack, 12 years ago)
  • django/core/cache/backends/memcached.py

    From b9c88c78827b848bdfaa5310f7c08b66437124fe Mon Sep 17 00:00:00 2001
    From: Sebastian Noack <sebastian.noack@gmail.com>
    Date: Fri, 12 Oct 2012 10:00:16 +0200
    Subject: [PATCH] Re-connect database and memcached after fork.
    
    ---
     django/core/cache/backends/memcached.py |    5 +++++
     django/db/backends/__init__.py          |   10 ++++++++++
     2 files changed, 15 insertions(+)
    
    diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
    index 9bb47c8..b8e3fa7 100644
    a b  
    22
    33import time
    44from threading import local
     5from multiprocessing.util import register_after_fork
    56
    67from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
    78
    class BaseMemcachedCache(BaseCache):  
    2526        self._lib = library
    2627        self._options = params.get('OPTIONS', None)
    2728
     29        def _after_fork(cache):
     30            cache._client = None
     31        register_after_fork(self, _after_fork)
     32
    2833    @property
    2934    def _cache(self):
    3035        """
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index 02d2a16..e84ca61 100644
    a b try:  
    44    from django.utils.six.moves import _thread as thread
    55except ImportError:
    66    from django.utils.six.moves import _dummy_thread as thread
     7from multiprocessing.util import register_after_fork
    78from contextlib import contextmanager
    89
    910from django.conf import settings
    class BaseDatabaseWrapper(object):  
    4142        self._thread_ident = thread.get_ident()
    4243        self.allow_thread_sharing = allow_thread_sharing
    4344
     45        def _after_fork(connection):
     46            connection.close()
     47
     48            connection.transaction_state = []
     49            connection.savepoint_state = 0
     50            connection._dirty = None
     51            connection._thread_ident = thread.get_ident()
     52        register_after_fork(self, _after_fork)
     53
    4454    def __eq__(self, other):
    4555        return self.alias == other.alias
    4656
Back to Top