<br><br><div><span class="gmail_quote">On 2/14/07, <b class="gmail_sendername">Greg Ewing</b> &lt;<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<a href="mailto:glyph@divmod.com">glyph@divmod.com</a> wrote:<br>&gt; On 08:52 pm, <a href="mailto:theller@ctypes.org">theller@ctypes.org</a> wrote:<br>&gt;<br>&gt;&nbsp;&nbsp;&gt;When I last looked at twisted (that is several years ago), there were
<br>&gt;&nbsp;&nbsp;&gt;several reactors - win32reactor, wxreactor, maybe even more.<br>&gt;<br>&gt; Only the very top-most level decides which reactor the application will use.<br><br>This is a worry, because it implies that there has to
<br>*be* a top level that knows what kind of reactor the<br>whole application will use, and all parts of the<br>application need to know that they will be getting<br>their reactor from that top level.<br><br>That may not be the case. For example, you want to
<br>incorporate some piece of event-driven code written<br>by someone else into your gtk application. But it<br>wasn&#39;t written with gtk in mind, so it doesn&#39;t know<br>to use a gtkreactor, or how to get a reactor that it
<br>can use from your application.<br><br>This is not my idea of what another poster called a<br>&quot;one-stop shop&quot; -- a common API that different pieces<br>of code can call independently without having to know<br>
about each other.<br><br>To my mind, there shouldn&#39;t be a &quot;reactor&quot; object<br>exposed to the application at all. There should just<br>be functions for setting up callbacks. The choice of<br>implementation should be made somewhere deep inside
<br>the library, based on what platform is being used.</blockquote><div><br>Eh, your own example seems to argue the opposite. If the choice for reactor was made somewhere deep inside the library, how does it know to use the GTK reactor? Only the code using GTK knows that it&#39;s going to need the GTK reactor. The generic code just uses whatever reactor was selected, automatically.
<br><br>The reason the decision should be made at the topmost level is that this is the most visible and adaptive location. A library or framework has to handle a boundless number of variations of environment, use and co-operation with other libraries and frameworks, whereas the topmost script knows exactly what it wants to do. A library that uses PyGTK can say &#39;I need the GTK reactor&#39;, but it would be wrong. All it needs is a reactor that interacts nicely with GTK. If there are multiple reactors that integrate nicely with GTK, there is no reason for the library to insist on one particular implementation. And it could be in the way, if a second library needs a different kind of integration and it knows of a reactor that supports both that *and* GTK integration. And if the whole system breaks, for some reason, the first place the programmer will look is in his own code, not deep inside another library.
<br></div><br>For what it&#39;s worth, I think a single event-handling mainloop API in the standard library is a *great* idea. Using part of Twisted for it (suitably adapted) is an even greater idea: a whole lot of work and brainpower went into Twisted&#39;s core, and it wasn&#39;t wasted. Duplicating the effort would be a big mistake and a terrible waste. A from-scratch implementation of an event-handling mechanism will not solve any of the &quot;issues&quot; most people have with Twisted. It will have many more bugs than Twisted (all the ones Twisted had and fixed, sometimes very obscure and hard-to-find bugs), it will not be significantly less complex (Twisted is as complex as it is because it had to be, to do what it is supposed to do) and it will not require any less of a brain-warp to understand (because that&#39;s just what event-driven programming takes.)
<br></div><br>If I wasn&#39;t short on free time (spending most of it on Py3k and, soon, py3k-forward-compatibility) I would do all the necessary Twisted-integration work myself :-) <br>-- <br>Thomas Wouters &lt;<a href="mailto:thomas@python.org">
thomas@python.org</a>&gt;<br><br>Hi! I&#39;m a .signature virus! copy me into your .signature file to help me spread!