This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyOS_InputHook broken
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mwh Nosy List: mdehoon, mwh
Priority: normal Keywords:

Created on 2004-09-19 10:27 by mdehoon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
readline.c.patch mdehoon, 2004-09-20 08:52 Patch for readline.c
Messages (9)
msg22487 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2004-09-19 10:27
PyOS_InputHook is a pointer to a function to be called
periodically when Python is idle. It is used, for
example, to get messages delivered to graphics windows.
In Python 2.3.4, calling PyOS_InputHook was handled by
readline via

rl_event_hook = PyOS_InputHook;
...   
p = readline(prompt);

The readline library takes care of calling
rl_event_hook (and hence PyOS_InputHook) ten times per
second while Python idles at the call to readline(prompt).

In Python 2.4a3, the call to readline is replaced by a
call to readline_until_enter_or_signal. Here, the
"select" function is used:

has_input = select(fileno(rl_instream) + 1, &selectset,
                                   NULL, NULL, NULL);
if(has_input > 0) {
                        rl_callback_read_char();
}

Now Python idles at "select", but PyOS_InputHook is not
being called. Instead, PyOS_InputHook gets called via
rl_event_hook at rl_callback_read_char. This means that
PyOS_InputHook is called once for every character the
user types, and is not called at all if the user is not
typing something.
msg22488 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-09-19 18:35
Logged In: YES 
user_id=6656

Well, this is probably my fault.  However, I'm about to go on 
holiday for a week and thinking about readline is definitely not 
part of my plans :-)

Can you work up a patch for this?  It shouldn't be terribly hard -- a 
non-NULL fifth argument to select seems in order.
msg22489 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-10-07 11:20
Logged In: YES 
user_id=6656

er, ping?  i'm willing to believe this is a fairly bad bug, but i could 
do with some encouragement to fix it :-)
msg22490 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2004-10-07 12:08
Logged In: YES 
user_id=488897

I submitted a patch a couple of weeks ago. Let me know if
you can't find it on sourceforge.
msg22491 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-10-07 12:10
Logged In: YES 
user_id=6656

Oops, didn't see the patch.  While I'm updating my checkout
and testing the patch, my first thought is that you probably
still want to assign to rl_event_hook, just in case we're
*not* using the callback interface to readline (old versions
of readline for example).
msg22492 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2004-10-07 12:21
Logged In: YES 
user_id=488897

That is right. I didn't think about that. You might consider
assigning to rl_event_hook inside the second
readline_until_enter_or_signal (the one if not
defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT)), because
it is only needed there. Though it probably wouldn't hurt to
set rl_event_hook for both cases.
msg22493 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-10-07 13:47
Logged In: YES 
user_id=6656

Ok, I made a couple of trivial changes, including moving the
rl_event_hook assignment.  Seems to work for me.

Modules/readline.c revision 2.78.

Thanks for the patch!
msg22494 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2004-10-19 09:08
Logged In: YES 
user_id=488897

Sorry for my late reply, I was out of town last week. I
tested the updated readline.c (using Python 2.4b1) and found
no problems on Cygwin, Linux, and Mac OS X. On Windows
(using the installer from the Python website),
PyOS_InputHook is still being called once for every command
by the user. However, this was also the case in older
versions of Python, and by looking at the source it seems
that this problem is in Parser/myreadline.c instead of
Modules/readline.c (I submitted a separate patch for that).
Anyway, Modules/readline.c seems to be working fine. Thanks
for helping me out.
msg22495 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-10-19 09:20
Logged In: YES 
user_id=6656

Glad to help.

Windows is *so* not my problem :)  Readline isn't used there, 
anyway (except for cygwin).
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 40930
2004-09-19 10:27:19mdehooncreate