This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Using subprocesses involves the global event loop #421
Closed
Description
Hello,
I'm the maintainer of pytest-asyncio. Pytest-asyncio allows users to block access to the global event loop, and pass the event loop explicitly; this is considered by some in the community as a best-practices approach.
However I've just received a bug report this approach doesn't work with subprocess (on Unix at least). Consider this test:
@pytest.mark.asyncio(forbid_global_loop=True)
async def test_subprocess(event_loop):
await asyncio.create_subprocess_shell('ls', loop=event_loop)
======================================================================== FAILURES ========================================================================
____________________________________________________________________ test_subprocess _____________________________________________________________________
event_loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
@pytest.mark.asyncio(forbid_global_loop=True)
async def test_subprocess(event_loop):
> await asyncio.create_subprocess_shell('ls', loop=event_loop)
tests/test_subprocess.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.5/asyncio/subprocess.py:197: in create_subprocess_shell
stderr=stderr, **kwds)
/usr/lib/python3.5/asyncio/base_events.py:1049: in subprocess_shell
protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
/usr/lib/python3.5/asyncio/unix_events.py:179: in _make_subprocess_transport
with events.get_child_watcher() as watcher:
/usr/lib/python3.5/asyncio/events.py:647: in get_child_watcher
return get_event_loop_policy().get_child_watcher()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pytest_asyncio.plugin.ForbiddenEventLoopPolicy object at 0x7f2050255588>
def get_child_watcher(self):
"Get the watcher for child processes."
> raise NotImplementedError
E NotImplementedError
/usr/lib/python3.5/asyncio/events.py:538: NotImplementedError
Two comments:
- can't the event_loop instance passed in be used for this functionality, instead of the global event loop policy? If an instance of the loop is provided, in my opinion asyncio shouldn't care about any globals.
- event_loop_policy.get_child_watcher() is undocumented as far as I can see.
Metadata
Metadata
Assignees
Labels
No labels