[Python-Dev] PyOS_InputHook and threads (original) (raw)
Michiel Jan Laurens de Hoon mdehoon at ims.u-tokyo.ac.jp
Wed Jan 12 08:38:30 CET 2005
- Previous message: [Python-Dev] PEP 246, redux
- Next message: [Python-Dev] PEP 246, redux
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I have started writing a patch that replaces PyOS_InputHook with PyOS_AddInputHook and PyOS_RemoveInputHook. I am a bit confused though on how hook functions are supposed to work with threads.
PyOS_InputHook is a pointer to a hook function, which can be defined for example in a C extension module.
When Python is running in a single thread, PyOS_InputHook is called ten times per second while Python is waiting for the user to type something. This is achieved by setting readline's rl_event_hook function to PyOS_InputHook.
When Python uses multiple threads, each thread has its own PyOS_InputHook (I am not sure if this was intended). However, with IDLE I noticed that the subprocess thread doesn't call its PyOS_InputHook. In IDLE (if I understand correctly how it works), one thread takes care of the GUI and the interaction with the user, while another thread executes the user's commands. If an extension module sets PyOS_InputHook, the PyOS_InputHook belonging to this second thread is set. However, this PyOS_InputHook does not get called. Is this simply an oversight? What would be a suitable place to add the call to PyOS_InputHook? In other words, where does the second thread go idle?
--Michiel.
On Thu, Dec 09, 2004, Michiel Jan Laurens de Hoon wrote:
My suggestion is therefore to replace PyOSInputHook by two functions PyOSAddInputHook and PyOSRemoveInputHook, 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.
-- 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
- Previous message: [Python-Dev] PEP 246, redux
- Next message: [Python-Dev] PEP 246, redux
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]