mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
check parents if we are in the worker. fix #348
This commit is contained in:
parent
326356a18c
commit
cdd3e1dc2b
@ -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
|
||||||
@ -98,6 +98,8 @@ MIDDLEWARE_CLASSES = (
|
|||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
# Uncomment the next line for simple clickjacking protection:
|
# Uncomment the next line for simple clickjacking protection:
|
||||||
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
# uncomment the next line to test multiprocessing
|
||||||
|
#'testing.apps.someapp.middleware.GunicornSubProcessTestMiddleware',
|
||||||
)
|
)
|
||||||
|
|
||||||
ROOT_URLCONF = 'testing.urls'
|
ROOT_URLCONF = 'testing.urls'
|
||||||
|
|||||||
@ -62,10 +62,12 @@ class GeventWorker(AsyncWorker):
|
|||||||
server = StreamServer(self.socket, handle=self.handle, spawn=pool)
|
server = StreamServer(self.socket, handle=self.handle, spawn=pool)
|
||||||
|
|
||||||
server.start()
|
server.start()
|
||||||
|
pid = os.getpid()
|
||||||
try:
|
try:
|
||||||
while self.alive:
|
while self.alive:
|
||||||
self.notify()
|
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)
|
self.log.info("Parent changed, shutting down: %s", self)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user