Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input hook is never called #1407

Open
mguijarr opened this issue Mar 30, 2021 · 0 comments
Open

input hook is never called #1407

mguijarr opened this issue Mar 30, 2021 · 0 comments

Comments

@mguijarr
Copy link
Contributor

mguijarr commented Mar 30, 2021

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant