[Python-Dev] Where to put the interrupt module?

Guido van Rossum guido@python.org
Fri, 13 Jun 2003 08:52:10 -0400


[Kevin J]
> That chunk of code is very problematic.  Some platforms/threading libraries
> will deliver a SIGINT to all threads, which can abort many system calls that
> are not trivially restarted/restartable.

While I was worried about this when writing the original code (that's
the only way to explain some of the things it does), I'm not sure if
we really have to worry about such platforms any more; I certainly
have never heard a report of such behavior.  On Unix and Unixish
systems, pthreads rule.  Windows doesn't have real signals.  Mac OS is
now also Unix.  PalmOS doesn't have threads.  What other platforms are
relevant?

> To deliver a KeyboardInterrupt
> only to the main thread is problematic, since the other threads may
> misinterpret the failure as something else (EOF, fatal error, or worse,
> operation succeeded).

*If* the other threads indeed get their syscalls interrupted, this
would indeed be a problem.

> I understand the desire to smooth over platform differences in
> Python, but I'm not sure that this one (signal delivery policy to
> threads) is a good idea.  In fact, I'll try to find a real-world
> case where this kind of error occurs.

I'd appreciate it if you found one.  Nevertherless, I'm not sure if
the weakening of semantics would make sense.  Better to fix the
offending platform (possibly by using pthreads :-).

[Just]
> > Naming: putting this into main sounds just right, but I would
> > suggest to call it sys.interrupt() instead of
> > sys.interrupt_main(). That way *if* we ever add the possibility to
> > interrupt a non-main thread, sys.interrupt() could grow an
> > optional argument specifying the thread.
> 
> I Agree.

Hm...  I like it better in the thread module, and there
"thread.interrupt()" looks wrong, while "thread.interrupt_main()"
makes sense.

If and when the generalized functionality is implemented, I think the
use cases will be so different that a different name for it won't be a
big burden.  I call YAGNI on the naming consideration.

--Guido van Rossum (home page: http://www.python.org/~guido/)