[Twisted-Python] Re: [Twisted-commits] r13446 - After a lengthy discussion, revert to previous threaded behavior wrt registering as the IO thread
Jp Calderone
exarkun at divmod.com
Sun Apr 3 12:50:39 MDT 2005
On Sun, 3 Apr 2005 13:31:08 -0400, James Y Knight <foom at fuhm.net> wrote:
>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?
Yes. Fortunately this never actually happens. When it becomes possible, we can think about fixing this behavior.
>
> 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()
Yes. A unit test like that _would_ be nice...
>
> > @@ -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.
Yes, however simply calling registerAsIOThread inside it is not a complete fix. The understanding to which I came is that the previous incorrectness was preferable to the new incorrectness.
Jp
More information about the Twisted-Python
mailing list