[Twisted-Python] PEP 342 now in python CVS

glyph at divmod.com glyph at divmod.com
Wed Aug 17 20:30:23 EDT 2005

On Thu, 18 Aug 2005 09:20:15 +1000, Christopher Armstrong <radeex at gmail.com> wrote:

>I'll just note that I am mostly alone amongst the developers of
>Twisted who think that this kind of cooperative threading + Deferred
>integration is a good idea. Glyph, Jp, and Allen Short (as he posted)
>have all said it's a bad idea to have such magical code. On the other
>hand, it's definitely not as bad as pre-emptive threading, where you
>basically can't know where context switches will happen.

Perhaps my opinion has glacially shifted over time, (I think I've always thought this way) but it's a bit more nuanced than that.  I think that there is some merit to synchronous-looking code in some situations.  I've written some networking code recently that had indentation 10-deep; this PEP might have really helped with that.

I think it's a good thing in some situations and will probably reduce the length of some of the nastiest parts of my Q2Q implementation (AKA "Divmod Vertex") by at least half.  However, it is limiting - it still doesn't expose the full power of a cooperative threading system.  At the same time, it provides some of the same implicit-state facilities that create problems with those same cooperative thread systems.  Depending on how it's regarded by Twisted developers, it could give us the bbest of both worlds or the worst of them.

How it's regarded is important because that will affect how it's used.  I believe that in particularly hairy code, it will probably help, and reduce bugs (code that already has hugely nested functions, that needs to be audited by 3 or 4 people before it works at all).  However, in average code it will likely be a source of them, since it tends to reduce line count at the cost of explicit transfer of control.  Since people like code that looks blocking a *whole lot*, and are willing to forego the benefits of event-driven programming most of the time (and by "most of the time" I mean the 90% of the world that doesn't even use Twisted, or any other event driven system), I am a bit concerned that this PEP will catch on like wildfire and Twisted programs will get a reputation for being really buggy and never handling edge cases or out-of-order input correctly.

So please, use this and enahnce your Twisted programs with it, but please tread lightly.  It's a powerful tool but it is still (perhaps even therefore) dangerous.

More information about the Twisted-Python mailing list