Inputhook for asyncio event loop integration.
(context)
| 39 | |
| 40 | |
| 41 | def 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 |
nothing calls this directly
no outgoing calls
no test coverage detected