开发者

wsgi in multijob mode

开发者 https://www.devze.com 2023-04-12 16:56 出处:网络
everyone. I have a simple wsgi server and a simple wsgi application. **The application** def app开发者_运维知识库(environ, start_response):

everyone. I have a simple wsgi server and a simple wsgi application.

**The application**

def app开发者_运维知识库(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/plain')])
    return ['Hello here']


**The server**

from wsgiref import simple_server
server = simple_server.WSGIServer(
        ('', 8080),
        simple_server.WSGIRequestHandler,
    )
server.set_app(app)
server.serve_forever()

Is there any way to handle any user's request in separate process or maybe thread (i.e. execute app code) without using external framework? There is no common data in the process or thread expected. If it's not possible, which way you can advise?


You may use ThreadingMixIn or ForkingMixIn from SocketServer module like this:

from wsgiref import simple_server
from SocketServer import ThreadingMixIn

class ThreadingWSGIServer (ThreadingMixIn, simple_server.WSGIServer): pass

server = ThreadingWSGIServer(...)
server.set_app(app)
server.serve_forever()

ForkingMixIn will not work on Windows, though.

Replace 'SocketServer' with 'socketserver' if you're using Python 3.

0

精彩评论

暂无评论...
验证码 换一张
取 消