MCPcopy Create free account
hub / github.com/ipython/ipython / inputhook

Function inputhook

IPython/terminal/pt_inputhooks/asyncio.py:41–63  ·  view source on GitHub ↗

Inputhook for asyncio event loop integration.

(context)

Source from the content-addressed store, hash-verified

39
40
41def inputhook(context):
42 """
43 Inputhook for asyncio event loop integration.
44 """
45 # For prompt_toolkit 3.0, this input hook literally doesn't do anything.
46 # The event loop integration here is implemented in `interactiveshell.py`
47 # by running the prompt itself in the current asyncio loop. The main reason
48 # for this is that nesting asyncio event loops is unreliable.
49 if PTK3:
50 return
51
52 # For prompt_toolkit 2.0, we can run the current asyncio event loop,
53 # because prompt_toolkit 2.0 uses a different event loop internally.
54
55 def stop():
56 loop.stop()
57
58 fileno = context.fileno()
59 loop.add_reader(fileno, stop)
60 try:
61 loop.run_forever()
62 finally:
63 loop.remove_reader(fileno)
64

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected