Message332771
`asyncio.create_subprocess_exec()` accepts a `loop` parameter, but doesn't use it to watch the child process. Instead uses `get_event_loop_policy().get_child_watcher()`, which doesn't doesn't know about `loop` but tries to use the current default event loop.
This fails if there is no current event loop or if that loop isn't running:
```
import asyncio
async def action(loop):
proc = await asyncio.create_subprocess_exec('echo', loop=loop)
await proc.wait()
loop = asyncio.new_event_loop()
loop.run_until_complete(action(loop))
loop.close()
```
This crashes because the main event loop never was created:
Traceback (most recent call last):
File "sample.py", line 8, in <module>
loop.run_until_complete(action(loop))
File "/home/sth/devel/cpython.vanilla/Lib/asyncio/base_events.py", line 589, in run_until_complete
return future.result()
File "sample.py", line 4, in action
proc = await asyncio.create_subprocess_exec('echo', loop=loop)
File "/home/sth/devel/cpython.vanilla/Lib/asyncio/subprocess.py", line 213, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
File "/home/sth/devel/cpython.vanilla/Lib/asyncio/base_events.py", line 1542, in subprocess_exec
transport = await self._make_subprocess_transport(
File "/home/sth/devel/cpython.vanilla/Lib/asyncio/unix_events.py", line 193, in _make_subprocess_transport
watcher.add_child_handler(transp.get_pid(),
File "/home/sth/devel/cpython.vanilla/Lib/asyncio/unix_events.py", line 924, in add_child_handler
raise RuntimeError(
RuntimeError: Cannot add child handler, the child watcher does not have a loop attached
If we do have a current event loop, for example by calling `asyncio.get_event_loop()` before creating out own loop, then we don't get an error, but the program hangs indefinitely since that loop isn't running.
Expected behavior would be that the loop given to create_subprocess_exec() is used to watch the child process. |
|
Date |
User |
Action |
Args |
2018-12-30 22:59:42 | sth | set | recipients:
+ sth, asvetlov, yselivanov |
2018-12-30 22:59:38 | sth | set | messageid: <1546210778.19.0.43686311162.issue35621@roundup.psfhosted.org> |
2018-12-30 22:59:38 | sth | link | issue35621 messages |
2018-12-30 22:59:38 | sth | create | |
|