<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 21 Οκτ 2013, at 10:32 μ.μ., Glyph <<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br>On Oct 20, 2013, at 2:21 AM, Orestis Markou <<a href="mailto:orestis@orestis.gr">orestis@orestis.gr</a>> wrote:<br><br><blockquote type="cite">Hello,<br><br>Short form of the question:<br><br>Are people using Twisted to host WSGI applications AND serve static files AND replace celery/redis/other?<br></blockquote><br>I'm not personally using it as a WSGI host, but otherwise, yes, a full-stack application container speaking multiple protocols.<br></blockquote><div><br></div><div>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:</div><div><br></div><div><div><font face="Courier">os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'</font></div><div><font face="Courier">application = django.core.handlers.wsgi.WSGIHandler()</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">wsgi_resource = WSGIResource(reactor, reactor.getThreadPool(), application)</font></div><div><font face="Courier">resource = Root(wsgi_resource)</font></div><div><font face="Courier"># this could probably be automatically inferred from settings.py</font></div><div><font face="Courier"><div>resource.putChild('static', File(...))</div></font></div><div><font face="Courier">resource.putChild('uploaded', File(...))</font></div><div><font face="Courier"># other stuff</font></div><div><font face="Courier"><div>site = server.Site(resource)</div><div>reactor.listenTCP(8000, site)</div><div>reactor.run()</div></font></div></div><br><blockquote type="cite"><blockquote type="cite">Are there any inherent drawbacks in using Twisted for this use case?<br></blockquote><br>Nope.  Twisted is the best :-).<br><br><blockquote type="cite">Long form of the question:<br><br>These days to get a reasonably feature-full python web stack deployed you need to have a lot of 3rd-party libraries.<br><br>The bare minimum looks probably like so:<br><br>1. Your web-framework of choice, like Django<br>2. Some kind of WSGI container, like gunicorn<br>3. A static file server, like nginx<br>4. Some kind of database [off-topic for this message]<br><br>Additionally, you might want:<br><br>* Celery<br>* Redis<br>* Cron<br>* Something for web sockets or similar technology<br>* … and so on<br><br>In my experience, Twisted can be used to replace a lot of those use cases:<br><br>* It has a WSGI container<br>* It has a static web server<br>* It can be used for other long-running tasks <br><br>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.<br></blockquote><br>If you hit any problems, they're bugs, report them and they'll get fixed.<br><br>Please do this.  I even gave a talk about this at DjangoCon a couple of years ago:<br><br><<a href="http://blip.tv/djangocon/keynote-glyph-lefkowitz-5573264">http://blip.tv/djangocon/keynote-glyph-lefkowitz-5573264</a>><br></blockquote><div><br></div><div>That was interesting to watch - I wonder if you know whether things have been improved since then. </div><div><br></div><div>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).</div><div><br></div><br><blockquote type="cite">-glyph<br><br><br><br>_______________________________________________<br>Twisted-Python mailing list<br><a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python<br></blockquote></div><br></body></html>