On Thu, 17 Mar 2005 10:29:09 -0700, Dustin Lee <qhfgva(a)gmail.com> wrote:
>So I've got a simple prototype of what I'm trying to achieve with my
> "queued tasks" xmlrpc server.
>
> I'd appreciate any comments, suggestions. So far it seems to work
> exactly I wanted but I have a feeling I'm abusing the intended use of
> deferreds. And that by polling I'm deviating from the twisted
> workflow model. But you have to start somewhere.
Yes, much abuse is present in this code. A couple grievous wrongs:
Deferreds (and almost all other Twisted APIs) are not thread-safe. You cannot invoke their methods in a thread other than that of the reactor.
The called and paused Deferred attributes are not really public. You should avoid using them if at all possible (and it almost always is). Likewise, the pause() and unpause() methods are more for the convenience of Deferred's implementation and you should never need to call them.
Attached is a modified version. It has a problem with shutdown, which I imagine is related to not properly closing the reactor's threadpool. Maybe someone else can suggest the correct way to deal with that.
Jp