[Twisted-Python] reactor.callLater(0,) should not be an idiom [PATCH]

Moshe Zadka twisted at moshez.org
Tue Oct 15 06:10:23 MDT 2002


This patch touches many places, so I wanted to run it by the list
first.

Thanks.

diff -ur -x CVS Twisted.clean/twisted/enterprise/reflector.py Twisted/twisted/enterprise/reflector.py
--- Twisted.clean/twisted/enterprise/reflector.py	Thu Oct 10 21:41:28 2002
+++ Twisted/twisted/enterprise/reflector.py	Tue Oct 15 07:06:14 2002
@@ -59,8 +59,8 @@
         # mainloop is not running.  I'm not sure what the correct behavior here
         # should be. --glyph
         
-        from twisted.internet import reactor
-        reactor.callLater(0, self._really_populate)
+        from twisted.internet import utils
+        utils.sched(self._really_populate)
 
     def _really_populate(self):
         """Implement me to populate schema information for the reflector.
diff -ur -x CVS Twisted.clean/twisted/internet/defer.py Twisted/twisted/internet/defer.py
--- Twisted.clean/twisted/internet/defer.py	Fri Sep 27 10:38:18 2002
+++ Twisted/twisted/internet/defer.py	Tue Oct 15 06:59:12 2002
@@ -40,10 +40,6 @@
     log.err(err)
     return err
 
-def _sched(m, r):
-    from twisted.internet import reactor
-    reactor.callLater(0, m, r)
-
 def succeed(result):
     d = Deferred()
     d.callback(result)
diff -ur -x CVS Twisted.clean/twisted/internet/udp.py Twisted/twisted/internet/udp.py
--- Twisted.clean/twisted/internet/udp.py	Mon Oct 14 13:30:09 2002
+++ Twisted/twisted/internet/udp.py	Tue Oct 15 06:59:35 2002
@@ -220,8 +220,8 @@
         """
         self.stopReading()
         if self.connected:
-            from twisted.internet import reactor
-            reactor.callLater(0, self.connectionLost)
+            from twisted.internet import utils
+            utils.sched(self.connectionLost)
 
     def connectionLost(self, reason=None):
         """Cleans up my socket.
diff -ur -x CVS Twisted.clean/twisted/internet/utils.py Twisted/twisted/internet/utils.py
--- Twisted.clean/twisted/internet/utils.py	Sun Oct 13 04:08:50 2002
+++ Twisted/twisted/internet/utils.py	Tue Oct 15 07:04:41 2002
@@ -70,3 +70,6 @@
 
 def getProcessValue(executable, args=(), env={}, path='.'):
     return callProtocolWithDeferred(_ValueGetter, executable, args, env, path)
+
+def sched(f, *args, **kw):
+    reactor.callLater(0, f, *args, **kw)
diff -ur -x CVS Twisted.clean/twisted/news/news.py Twisted/twisted/news/news.py
--- Twisted.clean/twisted/news/news.py	Thu Oct  3 09:40:32 2002
+++ Twisted/twisted/news/news.py	Tue Oct 15 07:00:42 2002
@@ -21,7 +21,7 @@
 """
 
 from twisted.protocols import nntp
-from twisted.internet import protocol, reactor
+from twisted.internet import protocol, reactor, utils
 
 import time
 
@@ -79,7 +79,7 @@
 
 
     def startFactory(self):
-        self._updateCall = reactor.callLater(0, self.syncWithRemotes)
+        self._updateCall = utils.sched(self.syncWithRemotes)
 
 
     def stopFactory(self):
diff -ur -x CVS Twisted.clean/twisted/protocols/ftp.py Twisted/twisted/protocols/ftp.py
--- Twisted.clean/twisted/protocols/ftp.py	Mon Oct 14 13:30:09 2002
+++ Twisted/twisted/protocols/ftp.py	Tue Oct 15 07:01:31 2002
@@ -71,7 +71,7 @@
 from math import floor
 
 # Twisted Imports
-from twisted.internet import abstract, reactor, protocol
+from twisted.internet import abstract, reactor, protocol, utils
 from twisted.internet.interfaces import IProducer
 from twisted.protocols import basic
 from twisted.internet.protocol import ClientFactory, ServerFactory, Protocol
@@ -146,7 +146,7 @@
 
     def stopProducing(self):
         self.request.unregisterProducer()
-        reactor.callLater(0, self.request.finish)
+        utils.sched(self.request.finish)
         self.request = None
 
 
diff -ur -x CVS Twisted.clean/twisted/test/test_ftp.py Twisted/twisted/test/test_ftp.py
--- Twisted.clean/twisted/test/test_ftp.py	Fri Sep  6 01:45:31 2002
+++ Twisted/twisted/test/test_ftp.py	Tue Oct 15 07:02:04 2002
@@ -16,7 +16,7 @@
 
 from pyunit import unittest
 from twisted.protocols import ftp, loopback
-from twisted.internet import reactor
+from twisted.internet import reactor, utils
 from twisted.internet.protocol import Protocol, FileWrapper, Factory, \
                                       ClientFactory
 
@@ -80,7 +80,7 @@
 
     def writeResponses(self, protocol, responses):
         for response in responses:
-            reactor.callLater(0, protocol.lineReceived, response)
+            utils.sched(protocol.lineReceived, response)
 
 
 class FTPServerTests(unittest.TestCase):
diff -ur -x CVS Twisted.clean/twisted/test/test_rebuild.py Twisted/twisted/test/test_rebuild.py
--- Twisted.clean/twisted/test/test_rebuild.py	Fri Sep 20 15:29:40 2002
+++ Twisted/twisted/test/test_rebuild.py	Mon Oct 14 08:00:37 2002
@@ -70,6 +70,7 @@
         else:
             b2 = myrebuilder.B()
             assert b2.b() == 'c'
+            print "MOSHE!!!!", b.b()
             assert b.b() == 'c'
         assert i.a() == 'd'
         assert a.a() == 'b'
diff -ur -x CVS Twisted.clean/twisted/web/static.py Twisted/twisted/web/static.py
--- Twisted.clean/twisted/web/static.py	Thu Oct 10 13:32:26 2002
+++ Twisted/twisted/web/static.py	Tue Oct 15 07:02:25 2002
@@ -196,8 +196,8 @@
     def upgradeToVersion5(self):
         if not isinstance(self.registry, Registry):
             self.registry = Registry()
-            from twisted.internet import reactor
-            reactor.callLater(0, _upgradeRegistry, self.registry)
+            from twisted.internet import utils
+            utils.sched(_upgradeRegistry, self.registry)
 
     def upgradeToVersion4(self):
         if not hasattr(self, 'registry'):
diff -ur -x CVS Twisted.clean/twisted/web/woven/template.py Twisted/twisted/web/woven/template.py
--- Twisted.clean/twisted/web/woven/template.py	Wed Oct  9 13:37:41 2002
+++ Twisted/twisted/web/woven/template.py	Tue Oct 15 07:02:49 2002
@@ -77,7 +77,7 @@
 
 from twisted.internet import defer
 from twisted.python import failure
-from twisted.internet import reactor, defer
+from twisted.internet import reactor, defer, utils
 from twisted.python import log
 
 from twisted.web.server import NOT_DONE_YET
@@ -195,7 +195,7 @@
                 raise AttributeError, "%s does not define self.templateFile to operate on" % self.__class__
             self.d = self.lookupTemplate(request)
         # Schedule processing of the document for later...
-        reactor.callLater(0, self.handleDocument, request, self.d)
+        utils.sched(0, self.handleDocument, request, self.d)
         #self.handleNode(request, self.d)
         #return str(self.d.toxml())
         





More information about the Twisted-Python mailing list