[Twisted-Python] patch for background processing (delay 0)

Bill la Forge laforge49 at yahoo.co.in
Wed May 19 00:03:27 EDT 2004


I do hereby consigne all copyrights for this patch to Glyph, as required 
by Twisted: http://www.twistedmatrix.com/developers/contributing
 
Appologies for not using diff, but I am not yet able to download the 
cygwin package. (perhaps Sunday bandwidth here will be better!)
 
The first part was developed by twisted:
 
    def callLater(self, _seconds, _f, *args, **kw):
        """See twisted.internet.interfaces.IReactorTime.callLater.
        """
        assert callable(_f), "%s is not callable" % _f
        assert sys.maxint >= _seconds >= 0, \
               "%s is not greater than or equal to 0 seconds" % (_seconds,)
# patch follows        
#        tple = DelayedCall(seconds() + _seconds, _f, args, kw,
        if _seconds != 0:
            ttc = _seconds + seconds()
        else:
            ttc = _seconds
        tple = DelayedCall(ttc, _f, args, kw,
# end of patch                           
                           self._pendingTimedCalls.remove,
                           self._resetCallLater)
        insort(self._pendingTimedCalls, tple)
        return tple

The second part is my contribution:
 
    def runUntilCurrent(self):
        """Run all pending timed calls.
        """
        if self.threadCallQueue:
            # Keep track of how many calls we actually make, as we're
            # making them, in case another call is added to the queue
            # while we're in this loop.
            count = 0
            for (f, a, kw) in self.threadCallQueue:
                try:
                    f(*a, **kw)
                except:
                    log.err()
                count += 1
            del self.threadCallQueue[:count]
        now = seconds()
# patch follows
#        while self._pendingTimedCalls and (self._pendingTimedCalls[-1].time <= now):
#            call = self._pendingTimedCalls.pop()
        do=[]
        while self._pendingTimedCalls and (self._pendingTimedCalls[-1].time <= now):
            do.append(self._pendingTimedCalls.pop())
        for call in do:
# end of patch
            try:
                call.called = 1
                call.func(*call.args, **call.kw)
            except:
                log.deferr()
                if hasattr(call, "creator"):
                    e = "\n"
                    e += " C: previous exception occurred in " + \
                         "a DelayedCall created here:\n"
                    e += " C:"
                    e += "".join(call.creator).rstrip().replace("\n","\n C:")
                    e += "\n"
                    log.msg(e)

Sincerly,
 


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


More information about the Twisted-Python mailing list