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.

Author mdehoon
Recipients
Date 2005-02-08.08:53:21
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=488897

I have written a patch that solves this problem more
generally via PyOS_InputHook, as suggested by Noam. This
patch also solves the related bugs #1053687, #798058, and
supersedes patch #1049855. The patch is available at
http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/inputhooks.diff

Currently, the EventHook function sits in a loop handling
Tcl events until keyboard input is detected. The presence of
Tcl events is checked every Tkinter_busywaitinterval
milliseconds. If a Tcl event arrives during this interval,
it won't be handled until the end of the interval. However,
with the default value of Tkinter_busywaitinterval = 20
milliseconds, that delay is not noticable.

Now consider the situation in which there can be more than
one input hook, for example set by different extension
modules. We cannot have EventHook sit in a loop until
keyboard input is detected, because that would prevent other
PyOS_InputHooks from being serviced. So in the EventHook in
the patch, the function returns immediately after handling
all Tcl events.

If we use Python from the command line and open a Tkinter label:
>>> from Tkinter import *
>>> l = Label()
then readline will call PyOS_InputHook ten times per second
while Python is idle. Because PyOS_InputHook points to
EventHook, we will return to the EventHook function almost
immediately. Effectively, we are then in the same situation
as before the patch. On Cygwin, however, previously mainloop
needed to be run in order for the label to appear; this is
no longer necessary with this patch. On Windows, currently
PyOS_InputHook is partially broken, as it is called only
once per command instead of ten times per second. This patch
fixed that also (same as patch #1049855).

If we have two or more input hooks, they are called
successively by readline. Since each input hook returns
after it has no more work to do, all of the input hooks are
guaranteed to be serviced.

To be able to have more than one input hook, we need to
replace PyOS_InputHook by three functions:
PyOS_AddInputHook, PyOS_RemoveInputHook, and
PyOS_CallInputHooks. For the third function, the
corresponding Python function call_input_hooks was created
in the readline module.

By adding a call to readline.call_input_hooks in run.py, as
suggested by Noam, all input hook functions are serviced
when IDLE is idle. So we can use Tkinter without calling
mainloop, and we can use other extension packages that use
input hooks. We can even do both:
>>> import Tkinter
>>> import gist # my extension module also needs input hooks
>>> Tkinter.Label() # label appears
>>> gist.window() # Graphics window appears.
works both with command-line python and IDLE.

I'm interested to hear your comments and suggestions. If
this patch seems like the way to go, I'd be happy to write
the documentation for it.
History
Date User Action Args
2007-08-23 15:38:37adminlinkissue989712 messages
2007-08-23 15:38:37admincreate