Nonblocking django? [closed]
Asked Answered
G

3

10

At work I'm not allowed to use perl for web services. Python is allowed however.

What I need to do is serve up the results of some very slow c++ binaries. Each exe takes up to 20 seconds to run. In perl I'd just use mojolicious's non blocking event loop ( an example.of which is given here. http://blogs.perl.org/users/joel_berger/2014/01/writing-non-blocking-applications-with-mojolicious-part-3.html )

How would one go about doing this with django and python?

Guitar answered 26/1, 2014 at 10:26 Comment(2)
Django is more about web-apps, not servers. You can use the built-in python module socket, which is very simple and low-level, or any of the reactor frameworks listed in the answers below (which are usually more powerful, but might be overkill, depending on what you're looking for)Scenography
What you really need is a port of AnyEvent::Util's fork_call (as I have been building myself with Mojo::IOLoop::ForkCall) and integrate it into some python event loop. Then again, you could talk your $work into letting you use the right tool for the job :-)Honduras
A
6

Tornado using non blocking IO , the concepts are the same as in perl or node js event loop, multiple tasks per thread and so on.

Anthracene answered 26/1, 2014 at 10:34 Comment(0)
W
4

Probably won't be possible with Django, as the entire framework will need to be built specifically for running inside an event loop. In an event-driven framework, slow operations (I/O for example) needs to be implemented using callbacks, so that the actual I/O can be offloaded to the event loop itself, and the callback only called when the operation has finished; Django is not implemented like this.

Take a look at Twisted — it is an event-driven networking engine for Python that also has some web application frameworks built on top of it.

Weston answered 26/1, 2014 at 10:33 Comment(0)
A
3

Take a look at A clean, lightweight alternative to Python's twisted. I'd choose gevent for a web app, as it runs with uWSGI--the most versatile web server to run Python code.

Aila answered 26/1, 2014 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.