Skip to content

input hook is never called #1407

Open
Open
@mguijarr

Description

@mguijarr

First of all, a million thanks for prompt-toolkit and ptpython 👍

I am trying to have a custom input hook getting called within a custom ptpython-based shell.
I followed instructions here: https://python-prompt-toolkit.readthedocs.io/en/stable/pages/advanced_topics/input_hooks.html?highlight=input%20hook
But, I must be doing something wrong : the custom hook is never called.

Here is an example to reproduce the problem with latest ptpython (3.0.16) and prompt toolkit (3.0.18):

Python 3.7.10 (default, Feb 26 2021, 18:47:35) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ptpython.repl import PythonRepl
>>> from prompt_toolkit.eventloop import set_eventloop_with_inputhook
>>> def my_hook(hook_context):
...   breakpoint() #this is just to see if this will be executed
... 
>>> set_eventloop_with_inputhook(my_hook)
<_UnixSelectorEventLoop running=False closed=False debug=False>
>>> pr=PythonRepl()
>>> pr.run()
>>> ... whatever I try, no breakpoint => my_hook is never called ...

Any idea what I am doing wrong ? Or maybe there is a bug here ?

My final goal is to have gevent loop integrated within the ptpython shell. My input hook would execute a gevent select on the file descriptor... (hope this can work).

In the past, I did this with custom event loop (see prompt-toolkit/ptpython#130) but since async io, I feel a bit desperate.

EDIT: gevent integration can be done quite easily in fact, by using aiogevent and calling asyncio.run(pr.run_async()) instead of run().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions