[Twisted-Python] A problem with runUntilCurrent

Bill la Forge laforge49 at yahoo.co.in
Mon May 17 11:04:38 EDT 2004

This is also problematic. What this code does is limit the number of
calls that will be made by runUntilCurrent. However, if there's code
that does a callLater with a delay of 0, it will always execute that.
The problem now is that only callLater's with a delay of 0 will be
executed. Yes, now the main loop runs fine, but the other timeouts
are prevented from running. 
I'm thinking that what you need to do is to have runUntilCurrent first
extract all the pending timed calls that it plans to execute, creating
a sub-list, and then call them. It takes two loops, not one.

Itamar Shtull-Trauring <itamar at itamarst.org> wrote:
On Mon, 2004-05-17 at 10:14, Bill la Forge wrote:

> This means that when you do a callLater with a delay of 0, 
> runUntilCurrent will immediately call the delayed function, which then
> calls callLater, and again the delayed function is immediately called,
> etc.

And that's why testImmediateThread failed. Attached is a fixed up patch
that solves that problem.

Index: base.py
--- base.py (revision 10658)
+++ base.py (working copy)
@@ -368,7 +368,11 @@
assert callable(_f), "%s is not callable" % _f
assert sys.maxint >= _seconds >= 0, \
"%s is not greater than or equal to 0 seconds" % (_seconds,)
- tple = DelayedCall(seconds() + _seconds, _f, args, kw,
+ if _seconds == 0:
+ tcc = 0
+ else:
+ tcc = seconds() + _seconds
+ tple = DelayedCall(tcc, _f, args, kw,
insort(self._pendingTimedCalls, tple)
@@ -416,7 +420,10 @@
count += 1
del self.threadCallQueue[:count]
now = seconds()
- while self._pendingTimedCalls and (self._pendingTimedCalls[-1].time <= now):
+ # make sure we don't run newly added calls, so we don't get into infinite loop
+ numCalls = len(self._pendingTimedCalls)
+ while numCalls and (self._pendingTimedCalls[-1].time <= now):
+ numCalls -= 1
call = self._pendingTimedCalls.pop()
call.called = 1

Bill la Forge
Yahoo! India Matrimony: Find your partner online.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20040517/cd589a6c/attachment.htm 

More information about the Twisted-Python mailing list