how to combine django plus gevent the basics?

前端 未结 1 1799
野的像风
野的像风 2020-12-07 22:16

After much searching and googling I am coming back to the well. I have Django 1.4 and am looking for a decent working example to figure out getting Django to work w

相关标签:
1条回答
  • 2020-12-07 22:25

    Here's how I run Django with gevent + monkey patching:

    1. I've modified manage.py so the first line (after the shebang) is from gevent import monkey; monkey.patch_all()

    2. I've added a new run_production_server script (see below).

    Finally, I've configured my front-end webserver to proxy requests to port 1234 (the port which run_production_server is listening on).

    from gevent import monkey; monkey.patch_all()
    from gevent.wsgi import WSGIServer
    
    from django.core.management import setup_environ    
    import settings
    setup_environ(settings)
    
    from django.core.handlers.wsgi import WSGIHandler as DjangoWSGIApp
    application = DjangoWSGIApp()
    server = WSGIServer(("127.0.0.1", 1234), application)
    print "Starting server on http://127.0.0.1:1234"
    server.serve_forever()
    

    Some might complain that this server isn't "web scale" enough. I doubt they would be able to provide benchmarks to prove that, but if you're worried you could also use gunicorn or uwsgi for your server. But this works just fine for me.

    0 讨论(0)
提交回复
热议问题