[Twisted-Python] Re: Transparent pooling of deferreds to be fired upon another
Terry Jones
terry at jon.es
Thu Apr 23 10:54:12 MDT 2009
Hi Andrew
>>>>> "Andrew" == Andrew Francis <andrewfr_ice at yahoo.com> writes:
Andrew> Why can't you have the callbacks attached to the deferred, share a flag?
Andrew> global flag
Andrew> def callback(....):
Andrew> global flag
Andrew> if flag == False:
Andrew> flag = True
Andrew> # do body of function
Andrew> else:
Andrew> # don't do anything - flag have been previously fired
Andrew> If I understand what is happening, this should work because of the
Andrew> non-preemptive nature of the reactor, that is you ought not get a
Andrew> race condition.
I'm not sure if I fully understand you.
1. If your callback above is the thing that does the work (i.e., my
alertSupervisor function), then yes, you could use a flag to make sure
the work is only done one.
2. If your callback really is a callback :-) then this doesn't seem to
address what I was after. It would stop the same piece of code in the
same file from doing something twice.
In the case of 1, I don't get what I want because I want various pieces of
code to be able to call the deferred-returning method and each of them to
get a valid deferred back, which fires as usual. I also don't get to call
the function and then call it again later, because the flag is one-shot.
I'm trying to deal with identical calls that happen more-or-less at the
same time.
In the case of 2, this is also not what I was after. I want, for example,
code running in a different process or on a different box to be able to
make the call (via RPC), get a deferred, etc. So a client-side solution
isn't going to work.
Or maybe you meant something else?
Sorry - I probably wasn't clear enough in my original post, and thanks for
the suggestion.
Terry
More information about the Twisted-Python
mailing list