PyOS_InputHook enhancement proposal
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. -- Michiel de Hoon, Assistant Professor University of Tokyo, Institute of Medical Science Human Genome Center 4-6-1 Shirokane-dai, Minato-ku Tokyo 108-8639 Japan http://bonsai.ims.u-tokyo.ac.jp/~mdehoon
On Thu, Dec 09, 2004, Michiel Jan Laurens de Hoon wrote:
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?
Because this is only for the C API, your best bet is to write a patch and submit it to SF. If people whine or it gets rejected, then write a PEP. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "19. A language that doesn't affect the way you think about programming, is not worth knowing." --Alan Perlis
Aahz wrote:
On Thu, Dec 09, 2004, Michiel Jan Laurens de Hoon wrote:
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?
Because this is only for the C API, your best bet is to write a patch and submit it to SF. If people whine or it gets rejected, then write a PEP.
I did modify the readline module that hooks this and can call back to a Python function. There are also methods for installing and removing the Python function. I did this for a different reason. I need Python signal handlers to run, and they don't run when the execution path is currently in some C code (such as readline). The hook forces the interpreter to run, and check for signals as a side effect. Using this I can be sitting in raw_input(), or interactive mode, and signal handlers are still run. If you want it, let me know. Actually, the modded readline module is part of pyNMS, on sourceforge. -- \/ \/ (O O) -- --------------------oOOo~(_)~oOOo---------------------------------------- Keith Dart <kdart@kdart.com> vcard: <http://www.kdart.com/~kdart/kdart.vcf> public key: ID: F3D288E4 URL: <http://www.kdart.com/~kdart/public.key> ============================================================================
Keith Dart <kdart@kdart.com> writes:
I did modify the readline module that hooks this and can call back to a Python function. There are also methods for installing and removing the Python function. I did this for a different reason. I need Python signal handlers to run, and they don't run when the execution path is currently in some C code (such as readline). The hook forces the interpreter to run, and check for signals as a side effect. Using this I can be sitting in raw_input(), or interactive mode, and signal handlers are still run.
Have you seen what happened to the signal handling code in readline in Python 2.4? I don't think your modifications will be needed anymore, but you should check. Cheers, mwh -- I don't remember any dirty green trousers. -- Ian Jackson, ucam.chat
participants (4)
-
Aahz
-
Keith Dart
-
Michael Hudson
-
Michiel Jan Laurens de Hoon