control-c and threads, signals in 2.3 causing all sorts of issues ['LBBW': checked]

Holger Joukl Holger.Joukl at LBBW.de
Fri Feb 20 03:11:14 EST 2004


Hi,
here is s.th. I used in a Python 1.5.2 app, maybe it can help:

import sys, signal
# a raw_input you can use with signal handlers
# the builtin raw_input raises a KeyboardInterrupt exception even if you
installed a signal handler
def my_raw_input(prompt):
    try:
        return raw_input(prompt)
    except KeyboardInterrupt:
        frame = sys.exc_info()[2].tb_frame
        sig = signal.SIGINT
        signal.getsignal(sig)(sig, frame) # call the signal handler for sig

__________________


Srikanth Mandava <Srikanth.Mandava at cosinecom.com> writes:

>     Hi!
>
>      When a signal handler is registered in the main thread and
>      "control-c" is entered, the child thread is getting the
>      KeyboardInterrupt exception(The documentation says the main thread
>      MUST receive the signal handler function call if handler is
>      registered).

Hmm.  Threads + signals == mwh running off screaming...

>      In python 2.2.1 the main thread was always called with
>      the sigint signal handler which was registered. In my case the
>      child thread is waiting on stdin using "raw_input" function. This
>      seems to be causing all sorts of strange behavior in the program
>      once the child thread gets the keyboardinterrupt exception and
>      eventually leading to seg fault on a sys exit .

Oh oh, if you're using raw_input(), readline might be getting
involved...

>      Any idea why this is happening in 2.3.1? This scenario worked in
>      2.2.1. Is this fixed in 2.3.2?.

Is this thread relavent?

http://groups.google.com/groups?threadm=a6562e06.0401061844.3269da85%40posting.google.com


OS, libc and versions of same might be useful, too.

Cheers,
mwh

--
  I located the link but haven't bothered to re-read the article,
  preferring to post nonsense to usenet before checking my facts.
                                      -- Ben Wolfson, comp.lang.python
--
 http://mail.python.org/mailman/listinfo/python-list

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.







More information about the Python-list mailing list