-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcms_gunicorn.py
45 lines (37 loc) · 1.51 KB
/
cms_gunicorn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
This file is created and updated by ansible, edit at your peril
"""
import multiprocessing
preload_app = True
timeout = 300
bind = "127.0.0.1:8010"
pythonpath = "/edx/app/edxapp/edx-platform"
workers = (multiprocessing.cpu_count()-1) * 2 + 2
def close_all_caches():
# Close the cache so that newly forked workers cannot accidentally share
# the socket with the processes they were forked from. This prevents a race
# condition in which one worker could get a cache response intended for
# another worker.
# We do this in a way that is safe for 1.4 and 1.8 while we still have some
# 1.4 installations.
from django.conf import settings
from django.core import cache as django_cache
if hasattr(django_cache, 'caches'):
get_cache = django_cache.caches.__getitem__
else:
get_cache = django_cache.get_cache
for cache_name in settings.CACHES:
cache = get_cache(cache_name)
if hasattr(cache, 'close'):
cache.close()
# The 1.4 global default cache object needs to be closed also: 1.4
# doesn't ensure you get the same object when requesting the same
# cache. The global default is a separate Python object from the cache
# you get with get_cache("default"), so it will have its own connection
# that needs to be closed.
cache = django_cache.cache
if hasattr(cache, 'close'):
cache.close()
def post_fork(server, worker):
close_all_caches()