[Pythonmac-SIG] signal module on the Mac
Jack Jansen
Jack.Jansen@oratrix.nl
Tue, 22 Jan 2002 22:05:22 +0100
On Tuesday, January 22, 2002, at 05:35 PM, Aureli Soria Frisch wrote:
> Hi,
>
> I want to catch a KeyboardInterrupt through Python on a Mac
> with MacOS8.6
> and Python version 2.0.
Are you sure you mean Python 2.0? That's pretty old, and as far
as I know there are no reasons for sticking with it (unlike
1.5.2, which was the last 68K version). The solution sketched
below will work for MacPython 2.2, but probably not for earlier
versions (maybe for 2.1.1, but I'm not sure).
>
> I know this is possible to do with the module signal in
> Unix-Python, but I
> cannot find this module in the mentioned Python distribution.
> The problem
> can not be easily be solved thorugh try/except.
The only reasonable alternative for try/except would be to
disable command-. processing with MacOS.SchedParams(), and then
test for cmd-. with Carbon.Evt.CheckEventQueueForUserCancel()
whenever it suits you. But be warned that if you do output to
the console window (or if there is any other reason why SIOUX,
the console handler, gets control) there is a good chance that
it will eat your cmd-. and you may get a KeyboardInterrupt
nonetheless.
For older Pythons this latter routine is not available and you
will have to write a fullblown event loop, I'm afraid.
--
- Jack Jansen <Jack.Jansen@oratrix.com>
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution --
Emma Goldman -