"Do this, and come back when you're done"

Peter Hansen peter at engcorp.com
Mon Dec 15 15:32:51 CET 2003

Valentino Volonghi aka Dialtone wrote:
> Kamus of Kadizhar <yan at NsOeSiPnAeMr.com> writes:
> > Is there any way to rewrite each half of the function to run in the
> > background, so to speak, and then have a master process that waits on
> > the results?  This would cut execution time in half more or less.
> Why don't you use twisted?  It's a net framework with a lot of
> protocols (and you can define your own ones) and it's based on async
> sockets which let you write programs avoiding threads for most of the
> times.
> www.twistedmatrix.com
> I'm sure you will find out that's the best thing ever done for python
> :)

I second that advice, and will also mention that it would avoid the sort
of bug that I pointed out in your first post, involving the simplistic
.recv(256) calls you are doing.  Twisted would make the code much more 
readable *and* reliable.  Well worth learning.  If you're doing this 
just to learn Python, you could do worse than get it working with Twisted,
then go poking into the Twisted internals to see how *it* works instead.


More information about the Python-list mailing list