Skip to content

Instantly share code, notes, and snippets.

@jamiesun
Created September 8, 2012 10:35
Show Gist options
  • Save jamiesun/3673325 to your computer and use it in GitHub Desktop.
Save jamiesun/3673325 to your computer and use it in GitHub Desktop.
gevent wsgi服务器定义,可利用多进程
class GEventServer():
""" gevent wsgi服务器定义,可利用多进程
"""
def __init__(self,handler,host,port):
self.handler = handler
self.host = host
self.port = port
def start(self):
from multiprocessing import Process
from gevent import monkey
monkey.patch_socket()
monkey.patch_os()
from gevent.wsgi import WSGIServer
server = WSGIServer((self.host, self.port), self.handler)
server.pre_start()
def serve_forever():
print 'starting server'
try:
server.start_accepting()
try:
server._stopped_event.wait()
except:
raise
except KeyboardInterrupt:
pass
for i in range(2):
Process(target=serve_forever, args=tuple()).start()
serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment