On 21 Οκτ 2013, at 10:32 μ.μ., Glyph <[email protected]> wrote:
> > On Oct 20, 2013, at 2:21 AM, Orestis Markou <[email protected]> wrote: > >> Hello, >> >> Short form of the question: >> >> Are people using Twisted to host WSGI applications AND serve static files >> AND replace celery/redis/other? > > I'm not personally using it as a WSGI host, but otherwise, yes, a full-stack > application container speaking multiple protocols. Any pointers on how to best use this in combination with WSGI/Django? In the past I had a combination of twisted-web (for /static and /media) and wsgi host (for everything else), all running under the same Service. Essentially: os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' application = django.core.handlers.wsgi.WSGIHandler() wsgi_resource = WSGIResource(reactor, reactor.getThreadPool(), application) resource = Root(wsgi_resource) # this could probably be automatically inferred from settings.py resource.putChild('static', File(...)) resource.putChild('uploaded', File(...)) # other stuff site = server.Site(resource) reactor.listenTCP(8000, site) reactor.run() >> Are there any inherent drawbacks in using Twisted for this use case? > > Nope. Twisted is the best :-). > >> Long form of the question: >> >> These days to get a reasonably feature-full python web stack deployed you >> need to have a lot of 3rd-party libraries. >> >> The bare minimum looks probably like so: >> >> 1. Your web-framework of choice, like Django >> 2. Some kind of WSGI container, like gunicorn >> 3. A static file server, like nginx >> 4. Some kind of database [off-topic for this message] >> >> Additionally, you might want: >> >> * Celery >> * Redis >> * Cron >> * Something for web sockets or similar technology >> * … and so on >> >> In my experience, Twisted can be used to replace a lot of those use cases: >> >> * It has a WSGI container >> * It has a static web server >> * It can be used for other long-running tasks >> >> I'd like to know if there is some kind of inherent drawback of using Twisted >> to fill those areas. My use case deals with many small intranet-like >> deployments of web applications, and I'd like to streamline the stack as >> much as possible. I believe that with the newly-released Crochet someone >> could even write a Django extension to replace `runserver` with something >> more production-oriented. > > If you hit any problems, they're bugs, report them and they'll get fixed. > > Please do this. I even gave a talk about this at DjangoCon a couple of years > ago: > > <http://blip.tv/djangocon/keynote-glyph-lefkowitz-5573264> That was interesting to watch - I wonder if you know whether things have been improved since then. Here's a thought experiment - I'd like to keep URL routing 100% in Django for anything that hits the DB. I have some code that needs to spawn an external process to generate an image on-demand (with a layer of caching on top). In the past I defined a Twisted.Web handler for that. Could I now expose an internal API that (through Crochet?) do the spawnProcess dance and come back with image data that Django could then handle internally (store in a file, whatever). How would the threaded WSGI container deal with the blocking request (not really blocking, but that request would stall until the Deferred would be fired). > -glyph > > > > _______________________________________________ > Twisted-Python mailing list > [email protected] > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
