durusmail: quixote-users: Deferrer: helper class for spawning single use threads
Deferrer: helper class for spawning single use threads
2004-02-28
Re: Deferrer: helper class for spawning single use threads
2004-03-04
Re: Deferrer: helper class for spawning single use threads
2004-03-04
2004-03-04
2004-03-05
Re: Deferrer: helper class for spawning single use threads
2004-03-05
Re: Deferrer: helper class for spawning single use threads
2004-03-05
Deferrer: helper class for spawning single use threads
Jason Sibre
2004-02-28
Hey folks,

I have something here that some of you might find useful.  It's a (probably
poorly named) module for handling tasks in a separate thread, and storing
the result until the original thread comes back to get it.  It isn't a tuple
space, but it was -in part anyway - inspired by the tuple space discussion
on this list a several months back relating to approaches on handling long
running requests.

If it's useful to anyone at all, it will most likely be useful to the people
who are running in a single process, single thread model.  Medusa users,
Twisted users (maybe... If I understand correctly, Twisted already has a
fairly spiffy way of handling this situation by adding things to the event
loop), possibly SCGI users (if I get SCGI correctly).  It's probably less
useful to FCGI folks, and a veritable waste of time for CGI users.

The module includes a Deferrer, which does the work, and a subclass of it,
QxDeferrer, which makes it a piece of cake to drop into an existing function
in a Quixote app, provided that function handles web requests.  It also has
a class used internally, and some module level functions to make working
with it as a semi-singleton a little more convenient.

It's not a magic bullet; it doesn't protect you from threaded programming
concerns.  It just makes it easy (in the medusa example) to kick off a
thread to do something, and let medusa get on with the business of serving
other requests while the long running request runs 'in the background'.
Meanwhile, the browser that made the request is in a Refresh loop ("your
request is being processed, please wait...")  until the processing is done,
at which time the result is displayed.

It works, but it's not much more than a proof of concept at this point; I
haven't had a real need for it so far, so it isn't well exercised.

The module includes some example code (both generic python, and Quixote
specific), and is moderately well documented.

If anyone has comments on it, good or bad, I'd like to hear them.  I don't
mess with threads too much, so I wouldn't be terribly surprised if I was
doing something dumb.


Jason Sibre
reply