Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check parents if we are in the worker. fix #348

  • Loading branch information...
commit cdd3e1dc2b6ea7b211f4c3159cbf91b6d5113cbf 1 parent 326356a
@benoitc authored
View
22 examples/frameworks/django/testing/testing/apps/someapp/middleware.py
@@ -0,0 +1,22 @@
+from multiprocessing import Process, Queue
+import requests
+import gevent
+
+def child_process(queue):
+ while True:
+ print queue.get()
+ requests.get('http://requestb.in/15s95oz1')
+
+class GunicornSubProcessTestMiddleware(object):
+ def __init__(self):
+ super(GunicornSubProcessTestMiddleware, self).__init__()
+ self.queue = Queue()
+ self.process = Process(target=child_process, args=(self.queue,))
+ self.process.start()
+
+ def process_request(self, request):
+ self.queue.put(('REQUEST',))
+
+ def process_response(self, request, response):
+ self.queue.put(('RESPONSE',response.status_code))
+ return response
View
2  examples/frameworks/django/testing/testing/settings.py
@@ -98,6 +98,8 @@
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+ # uncomment the next line to test multiprocessing
+ #'testing.apps.someapp.middleware.GunicornSubProcessTestMiddleware',
)
ROOT_URLCONF = 'testing.urls'
View
4 gunicorn/workers/ggevent.py
@@ -62,10 +62,12 @@ def run(self):
server = StreamServer(self.socket, handle=self.handle, spawn=pool)
server.start()
+ pid = os.getpid()
try:
while self.alive:
self.notify()
- if self.ppid != os.getppid():
+
+ if pid == os.getpid() and self.ppid != os.getppid():
self.log.info("Parent changed, shutting down: %s", self)
break
Please sign in to comment.
Something went wrong with that request. Please try again.