Created
September 8, 2012 10:35
-
-
Save jamiesun/3673325 to your computer and use it in GitHub Desktop.
gevent wsgi服务器定义,可利用多进程
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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