[Twisted-Python] concurrency via reactor

Hi! I am writing some code which requires synchronization between several TCP clients. I have several connections and at some point I have to wait for data becoming availiable from several of them. Kind of "barrier" pattern. I am twising my head how to do it with twisted using reactor. Could somebody point me into right direction? Thanks! Vadim

On Wed, 24 Sep 2008 12:16:29 -0700, Vadim Zaliva <krokodil@gmail.com> wrote:
Hi!
I am writing some code which requires synchronization between several TCP clients. I have several connections and at some point I have to wait for data becoming availiable from several of them. Kind of "barrier" pattern. I am twising my head how to do it with twisted using reactor. Could somebody point me into right direction? Thanks!
You might want twisted.internet.defer.gatherResults(). It accepts a list of Deferreds and returns a Deferred that fires when they all fire. Jean-Paul

On Sep 24, 2008, at 12:19, Jean-Paul Calderone wrote:
Hi!
I am writing some code which requires synchronization between several TCP clients. I have several connections and at some point I have to wait for data becoming availiable from several of them. Kind of "barrier" pattern. I am twising my head how to do it with twisted using reactor. Could somebody point me into right direction? Thanks!
You might want twisted.internet.defer.gatherResults(). It accepts a list of Deferreds and returns a Deferred that fires when they all fire.
Jean-Paul, Thanks! Seems like what I need. The only thing missing is ability to specify timeout parameters, how long to wait for deferred to fire. Sincerely, Vadim

On Sep 24, 2008, at 12:19, Jean-Paul Calderone wrote:
You might want twisted.internet.defer.gatherResults(). It accepts a list of Deferreds and returns a Deferred that fires when they all fire.
Pardon my naive questions, but how I can easily call gatherResults() to wait for all deferred to fire and to return list of results in form of list of (success,result) tuples? Vadim

On Sep 24, 2008, at 16:22, Vadim Zaliva wrote:
Pardon my naive questions, but how I can easily call gatherResults() to wait for all deferred to fire and to return list of results in form of list of (success,result) tuples?
Never mind. I have managed to do it in asynchronous manner, via callbacks. Vadim
participants (3)
-
Jean-Paul Calderone
-
Mike Pelletier
-
Vadim Zaliva