[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 23:52:34 EDT 2005


> [23:46] <exarkun> So, um, to back up and perhaps narrow scope slightly
> [23:46] <exarkun> The current code does the right thing, I think, 
> except when the platform lacks threads
> [23:46] <exarkun> it does more than it needs to, probably, but it 
> doesn't look like it ever does anything that's plain wrong
> [23:47] <exarkun> platforms that lack thread support need to just not 
> have registerAsIOThread called, or registerAsIOThread needs to be a 
> no-op on those platforms

It already is, and always has been. From The Source:

def registerAsIOThread():
     """Mark the current thread as responsable for I/O requests.
     """
     global threaded
     global ioThread
     if threaded:
         import thread
         ioThread = thread.get_ident()


> [23:48] <exarkun> Correction: registerAsIOThread in __init__ on a 
> thread-supporting platform is also sub-optimal now, as it forces the 
> import of the thread module when we may not actually need it.

But it doesn't. See above. It is *because* of the behavior of doing 
nothing when threadable.init(1) has not yet been called that 
whenThreaded(registerAsIOThread) is necessary.

> [23:54] <glyph> Yes, but having iterate() behave in random, 
> non-deterministic, broken ways in edge cases is preserving its current 
> behavior :)

So, the reasoning for re-breaking iterate() is that iterate is also 
broken in some other way, and thus it should remain broken in this 
regard too? How does that even make a bit of sense?

Of course, right now, the only place isInIOThread is ever used in 
twisted is in reactor's wakeUp function, and there, it does not matter 
(except for efficiency) that it will always return False. So, we could 
simplify isInIOThread to "return False" and call it a feature.

A better solution may be to get rid of all this mess, and just make it 
so that if the thread module is available, it is used. Forget the 
"threaded mode" nonsense, and just make threaded-or-not something that 
has to be determined once, and finally, at startup.

James





More information about the Twisted-Python mailing list