Wait, why isn't that just a bug that wait() doesn't know the associated
loop?

It seems the child watcher is only associated with the loop on
set_event_loop(), which in your example doesn't get called (and it
shouldn't need to be called).

I've reproduced your bug; please file a bug per Victor's instructions.

--Guido

On Sun, Aug 9, 2015 at 5:00 PM, <chetanre...@gmail.com> wrote:

> 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
>
>


-- 
--Guido van Rossum (python.org/~guido)

Reply via email to