PyOS_InputHook enhancement proposal

U

umdehoon

PyOS_InputHook is a pointer to a function that is called periodically (ten
times per second) while Python is idle, for example, when waiting for a
user command. Python C extension modules can set this pointer to a hook
function defined in the extension module. For example, _tkinter.c makes
use of PyOS_InputHook to get messages delivered to its widgets.

A problem arises when two or more extension modules want to set
PyOS_InputHook. For example, the scientific plotting package pygist needs
PyOS_InputHook to get messages delivered to its graphics windows, and may
therefore conflict with the Python GUI IDLE, which uses Tkinter. Chaining
won't work, as it will fail when an extension module wants to remove its
hook function.

My suggestion is therefore to replace PyOS_InputHook by two functions
PyOS_AddInputHook and PyOS_RemoveInputHook, and let Python keep track of
which hooks are installed. This way, an extension module can add a hook
function without having to worry about other extension modules trying
to use the same hook.

Any comments? Would I need to submit a PEP for this proposal?

--Michiel, U Tokyo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top