Hello,
I tried to run the following program with Python-3.5.0b4, and it hangs
forever:
--------------------------------------------
import asyncio
async def sleepWithShell(loop):
process = await asyncio.create_subprocess_shell("sleep 2", loop=loop)
await process.wait()
return True
async def sleepWithAsyncio(loop):
await asyncio.sleep(2, loop=loop)
return True
def main():
loop = asyncio.new_event_loop()
coros = [ sleepWithShell(loop) for i in range(5)]
results = loop.run_until_complete(asyncio.gather(*coros, loop=loop))
loop.close()
print(results)
if __name__ == "__main__":
main()
----------------------------------------------
In main, if you replace sleepWithShell with sleepWithAsyncio the program
will run as expected. I looked through the code, and I now understand that
process.wait doesn't work because the child process watcher is not
associated with the loop that's passed.
In an ideal world, i'd like to be able to create a loop, use it and close
it without changing any global state. It seems like that's possible with
some coroutines, but not with create_subprocess_shell.
If passing a custom loop to create_subprocess_shell isn't always supported,
I was wondering if it's possible to check and raise an exception in
subprocess.Process.wait instead of just hanging forever.
Thanks,
Chetan