[Twisted-Python] Re: [Twisted-commits] r13446 - After a lengthy discussion, revert to previous threaded behavior wrt registering as the IO thread

James Y Knight foom at fuhm.net
Sun Apr 3 13:31:08 EDT 2005


On Apr 3, 2005, at 1:58 AM, Jp Calderone wrote:
> After a lengthy discussion, revert to previous threaded behavior wrt  
> registering as the IO thread

> Modified: trunk/twisted/internet/posixbase.py
> ======================================================================= 
> =======
> --- trunk/twisted/internet/posixbase.py	(original)
> +++ trunk/twisted/internet/posixbase.py	Sat Apr  2 23:58:11 2005
> @@ -155,7 +155,6 @@
>          ReactorBase.__init__(self)
>          if self.usingThreads or platformType == "posix":
>              self.installWaker()
> -        threadable.whenThreaded(threadable.registerAsIOThread)
>
>      def _handleSignals(self):
>          """Install the signal handlers for the Twisted event loop."""

You **do** realize this means isInIOThread always returns false after  
threading is enabled, if the reactor was started before threading was  
enabled, right?

Something like the following should be run in the test suite. It has to  
be in a separate process, though, to ensure it's in the incorrect  
state, so something needs to be done about passing in the reactor to  
run, also.

from twisted.python import threadable
from twisted.internet import reactor

def testIsInIOThread():
     print "1)", threadable.isInIOThread()
     threadable.init(1)
     print "2)", threadable.isInIOThread()
     reactor.crash()

reactor.callWhenRunning(testIsInIOThread)
reactor.run()

> @@ -202,10 +201,6 @@
>          self.startRunning(installSignalHandlers=installSignalHandlers)
>          self.mainLoop()
>
> -    def iterate(self, delay=0):
> -        threadable.registerAsIOThread()
> -        ReactorBase.iterate(self, delay)
> -
>      def mainLoop(self):
>          while self.running:
>              try:

iterate() is the external API, I think it, like startRunning, should  
also ensure the thread it's being called on is marked as the IO thread.

James





More information about the Twisted-Python mailing list