Python Asynchronous Services

Moshe Zadka m at moshez.org
Thu Jul 17 08:05:46 EDT 2003


On Thu, 17 Jul 2003, "Graeme Matthew" <gsmatthew at ozemail.com.au> wrote:

> Hi all, I have hit a serious snag ...
...
> please any help or examples as I have now been on this for 2 days without
> any luck. I have looked at asyncore and asynchat, problem is once the server
> socket input is completed then their will be an area that is CPU bound where
> it will need to call the model, database etc and produce the html request,
> this means that control will only be handed back to IO operations when this
> is finished, effectively blocking all other requests  ....

Well, I can recommend Twisted. Twisted uses a producer/consumer model
to send large file, which is fairly transparent [there is a good
cut'n'pastable example of usage of this in twisted.web.static.File].
This should be enough to handle the network part. You claim there
is a CPU-bound operation after that -- if this is really true [and
in my experience, in many of the cases the operation are short enough
that it is not required] -- you can use Twisted's deferToThread to
treat those operations as though they were completely asynchronous.
This uses Twisted's internal threadpool support.

More information: http://twistedmatrix.com/
[Disclaimer: I am part of the Twisted developement team]
-- 
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/





More information about the Python-list mailing list