[Python-Dev] Signals+Threads (PyGTK waking up 10x/sec).

Adam Olsen rhamph at gmail.com
Sun Dec 9 03:22:15 CET 2007

On Dec 8, 2007 6:54 PM, Guido van Rossum <guido at python.org> wrote:
> On Dec 8, 2007 5:30 PM, Adam Olsen <rhamph at gmail.com> wrote:
> > On Dec 8, 2007 5:21 PM, Guido van Rossum <guido at python.org> wrote:
> > > Hm... Does this mean you're *always* creating an extra thread to handle signals?
> >
> > Yup, Py_Initialize will do it.
> That's unacceptable. It must be possible to build Python without
> threads (and still support signals -- in fact one could argue that
> signals make *more* sense when there are no threads :-).

For my patch it won't make much sense to disable threads, so I don't
mind taking liberties there.

> [...]
> > To summarize, there's two problems to be solved:
> > 1) low-level corruption in the signal handlers as they record a new
> > signal, such as in Py_AddPendingCalls
> This is purely theoretical, right? Has anyone ever observed this?

I've never heard of it happening.  If the compiler doesn't do much
reordering (the CPU isn't an issue as this is only called in the main
thread) then the most you might get is dropped calls.

It's fairly safe the way signal handlers use it, but they'd work just
as well (and easier to understand/verify) without the whole queue
aspect; just setting some flags and resetting _Py_Ticker.

> > 2) high-level wakeup race: "check for pending signals, have a signal
> > come in, then call a blocking syscall/library (oblivious to the new
> > signal)."
> Right. That's the race which really does happen, and for which the
> current lame-y work-around is to use a short timeout.
> [...]
> > > Anyway, I would still like to discuss this on #python-dev Monday.
> > > Adam, in what time zone are you? (I'm PST.) Who else is interested?
> >
> > MST.
> Unfortunately I can't stay at work later than 5:30 or so which would
> be too early for you I believe. I could try again after 8pm, your 9pm.
> Would that work at all? Otherwise I'd rather try earlier in the day if
> that works at all for you.

5:30 am or 5:30 pm?  Any time after 11 am MST (10 am PST) should be
fine for me.  (My previous email was a little naive about how late I
get up.)  I shouldn't be gone until around midnight MST.

Adam Olsen, aka Rhamphoryncus

More information about the Python-Dev mailing list