[Twisted-Python] succeedForOneOf
I wrote succeedForOneOf to help when I want to loop through a list and call a function with the item from the list as the first argument to the function, and stop when one of the function calls succeeds. The use case I need it for is, connecting to multiple servers looking for a particular thing, and stopping when I find it. In my testing in the attached file, succeedForOneOf does what I would expect. However, when I tried this in my application, and func involved connecting to servers via PB and calling a remote method, it started up a ton of 'PBClientFactory's until the win32eventreactor spun wildly out of control because I exceeded the 64 object limitation. This of course also caused the server I was connecting to to spin wildly out of control as well, sucking up all of the CPU. My question isn't related to the win32event reactor problem. I just don't understand why my implementation of succeedForOneOf would fail in this manner. Does anyone see a problem with the code? Has someone else written code to accomplish this in a different way? -Justin
Well the answer was terribly obvious. I needed to cache my connections and reuse them instead of making new connections all the time. I was confused by the fact that this worked previously in my code, but it has evolved some since then. Anyway, the attached code works fine. On Thu, 20 Jan 2005 10:24:12 -0600, Justin Johnson <justinjohnson@gmail.com> wrote:
I wrote succeedForOneOf to help when I want to loop through a list and call a function with the item from the list as the first argument to the function, and stop when one of the function calls succeeds. The use case I need it for is, connecting to multiple servers looking for a particular thing, and stopping when I find it.
In my testing in the attached file, succeedForOneOf does what I would expect. However, when I tried this in my application, and func involved connecting to servers via PB and calling a remote method, it started up a ton of 'PBClientFactory's until the win32eventreactor spun wildly out of control because I exceeded the 64 object limitation. This of course also caused the server I was connecting to to spin wildly out of control as well, sucking up all of the CPU.
My question isn't related to the win32event reactor problem. I just don't understand why my implementation of succeedForOneOf would fail in this manner. Does anyone see a problem with the code? Has someone else written code to accomplish this in a different way?
-Justin
participants (1)
-
Justin Johnson