[Python-bugs-list] PRIVATE: Threads and readline (PR#120)

xfb52@dial.pipex.com xfb52@dial.pipex.com
Fri, 29 Oct 1999 14:33:57 -0400 (EDT)


Full_Name: Alex Zbyslaw
Version: 1.5.2
OS: FreeBSD 3.2
Submission from: useraq64.uk.uudial.com (62.188.136.124)


When python is compiled with thread support and readline, ^C no longer
works properly (interpreter goes into an infinite loop).
(Tried with readline 2.0, 2.2 and 4.0).

The same system compiled without readline but with threads works fine,
and compiled without threads but with readline works fine.

The error seems to centre around the signal handler installed by
call_readline in Modules/readline.c which does not call signal_handler
in Modules/signalmodule.c (which is what happens without readline).

I have found an inadequate fix which works with readline-4.0 (but
not earlier realeases).  This makes ^C work but only after a RETURN
is pressed.  Whilst not perfect, it does at least allow readline
and threads.

Hopefully this may point someone who can better understand the signal
handling to find a better fix.

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.

--Alex

*** Modules/readline.c  Fri Oct 29 19:31:13 1999
--- Modules/readline.c.ORIG     Fri Oct 29 19:14:27 1999
***************
*** 34,40 ****
  extern int rl_bind_key_in_map();
  extern int rl_initialize();
  extern int add_history();
- extern int rl_catch_signals;
  extern Function *rl_event_hook;
  #endif
  
--- 34,39 ----
***************
*** 233,239 ****
  static void
  setup_readline()
  {
-         rl_catch_signals=0;
        rl_readline_name = "python";
        /* Force rebind of TAB to insert-tab */
        rl_bind_key('\t', rl_insert);
--- 232,237 ----
***************
*** 277,283 ****
        int n;
        char *p;
        RETSIGTYPE (*old_inthandler)();
! /*    old_inthandler = signal(SIGINT, onintr); */
        if (setjmp(jbuf)) {
  #ifdef HAVE_SIGRELSE
                /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */
--- 275,281 ----
        int n;
        char *p;
        RETSIGTYPE (*old_inthandler)();
!       old_inthandler = signal(SIGINT, onintr);
        if (setjmp(jbuf)) {
  #ifdef HAVE_SIGRELSE
                /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */
***************
*** 288,294 ****
        }
        rl_event_hook = PyOS_InputHook;
        p = readline(prompt);
! /*    signal(SIGINT, old_inthandler); */
        if (p == NULL) {
                p = malloc(1);
                if (p != NULL)
--- 286,292 ----
        }
        rl_event_hook = PyOS_InputHook;
        p = readline(prompt);
!       signal(SIGINT, old_inthandler);
        if (p == NULL) {
                p = malloc(1);
                if (p != NULL)