On 20/01/20 10:55, Stefan Hajnoczi wrote: >> >> [1] https://qemu.readthedocs.io/en/latest/interop/live-block-operations.html > John and I discussed async events in the past. qmp-shell currently uses > the input() built-in function. If we modify it with a > select(2)/poll(2)-style function that monitors both stdin and the QMP > socket then it could print QMP events as soon as they are received.
I think it should be rewritten using async/await. A simple example: import asyncio import sys from concurrent.futures import ThreadPoolExecutor async def ainput(prompt: str = ""): with ThreadPoolExecutor(1, "ainput") as executor: return (await asyncio.get_event_loop().run_in_executor( executor, sys.stdin.readline )).rstrip() async def numbers(): i = 1 while True: print(i) i = i + 1 await asyncio.sleep(1) async def main(): name = await ainput("What's your name? ") print("Hello, {}!".format(name)) asyncio.get_event_loop().create_task(numbers()) asyncio.get_event_loop().run_until_complete(main()) This would be a great Summer of Code project. Even an autocompletion interface using readline should be possible. Paolo