A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20071208/66fe9718/attachment.htm below:

On 08/12/2007, <b class="gmail_sendername">Guido van Rossum</b> &lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Dec 8, 2007 3:58 AM, Gustavo Carneiro &lt;<a href="mailto:gjcarneiro@gmail.com">gjcarneiro@gmail.com</a>&gt; wrote:<br>&gt; Not only that, but pygtk is a generic module;<br><br>What does &quot;generic&quot; mean in this context? Surely not that it applies
<br>to other libraries than GTK?</blockquote><div><br>Well, actually this is also a PyGObject issue, not only PyGtk.&nbsp; PyGObject wraps GLib.&nbsp; GLib was created to serve the needs of Gtk+, but is useful by itself for writing portable programs.&nbsp; Among other things, GLib offers a generic &quot;main loop&quot;, which programs can use to do generic event-driven programming, such as timeouts, polling file descriptors, and doing other work when the main loop becomes idle.
<br><br>You could argue that non-gtk programs are rare and we shouldn&#39;t worry too much about them.&nbsp; Maybe it&#39;s true, I don&#39;t know.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&gt; who are we to forbid the usage<br>&gt; of signals if python itself allows it?&nbsp;&nbsp;If we were to ignore signals then<br>&gt; sooner or later someone would come along and shout &quot;hey, signals work just<br>&gt; fine in pure python, so why did pygtk have to break my signals?&quot;.
<br><br>Um, signals don&#39;t &quot;work just fine&quot; in pure Python. And I would argue<br>they don&#39;t either in C. They are extremely subtle, and most code using<br>signals is broken in some way. Just try to read the sigaction() man
<br>page and claim you understand it.<br><br>Unfortunately, in Unix there are some conditions that can only be<br>delivered using signals (e.g. SIGINTR, SIGTERM) and others for which<br>your choices are either polling or signals (SIGCHILD, SIGWINCH).
<br>Traditionally, solutions based on select() or poll() with a short<br>timeout (e.g. 20 or 100 ms) have worked well, as the number of<br>instructions executed each time is really negligeable, and the<br>response time is still reasonable on a human time scale. Unfortunately
<br>it seems recent developments in power management for ultra-low power<br>devices have made this an issue again.<br><br>Windows solves this more elegantly by having a unified &quot;wait for<br>multiple conditions&quot; system call which can wait on I/O, semaphores,
<br>and other events (within the same process or coming from other<br>processes). Unfortunately, in Unix, some events don&#39;t have a file<br>descriptor associated with them, and for those select()/poll() cannot<br>be used.
<br><br>The best solution I can think of is to add a new API that takes a<br>signal and a file descriptor and registers a C-level handler for that<br>signal which writes a byte to the file descriptor. You can then create<br>
a pipe, connect the signal handler to the write end, and add the read<br>end to your list of file descriptors passed to select() or poll(). The<br>handler must be written in C in order to avoid the race condition<br>referred to by Glyph (signals arriving after the signal check in the
<br>VM main loop but before the select()/poll() system call is entered<br>will not be noticed until the select()/poll() call completes).</blockquote><div><br></div></div>Funny that everyone mentions this solution, as it is the solution implemented by my patch :-)
<br><br>Well, to be fair, it might not be _exactly_ what is implemented by the patch.&nbsp; Reading between the lines, I think what you mean is to have python&#39;s C signal handler mostly untouched; it would only write a byte to a pipe _in addition to_ the normal setting the flag and Py_AddPendingCall.
<br><br>The patch I submitted, on the other hand, completely removes the vector of flags and Py_AddPendingCall, and instead writes the number of the signal that was raised into the pipe, and reads it back from the pipe in the Python main loop.
<br><br>Which is the best solution?&nbsp; I think my patch fixes two problems: 1. the need to have a FD to wake up poll() (t o fix the problem with what we are discussing in this thread), and 2. make Python&#39;s signal handling more reliable (not 100% reliable because it doesn&#39;t handle longer bursts of signals than the pipe buffer can take, but at least is race free).
<br><br>My solution is being reject because people are afraid to touch the signal handling code, which has its faults, but well know faults.&nbsp; But if I refactor the patch to keep the crappy-but-sort-of-working signal code, and only enhance it with the pipe, maybe it will more likely get accepted.
<br><br>Do I understand correctly? :-)<br><br>-- <br>Gustavo J. A. M. Carneiro<br>INESC Porto, Telecommunications and Multimedia Unit<br>&quot;The universe is always one step beyond logic.&quot; -- Frank Herbert

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4