Skip to content

Commit 8e76a4a

Browse files
cectonasvetlov
authored andcommitted
Add automatically a SafeChildWatcher to the test loop (#2075)
The fact that on Unix system we don't create automatically a child watcher makes all call to asyncio.create_subprocess_* to fail.
1 parent f59e5c4 commit 8e76a4a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

aiohttp/test_utils.py

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import functools
66
import gc
77
import socket
8+
import sys
89
import unittest
910
from abc import ABC, abstractmethod
1011
from contextlib import contextmanager
@@ -446,6 +447,11 @@ def setup_test_loop(loop_factory=asyncio.new_event_loop):
446447
"""
447448
loop = loop_factory()
448449
asyncio.set_event_loop(None)
450+
if sys.platform != "win32":
451+
policy = asyncio.get_event_loop_policy()
452+
watcher = asyncio.SafeChildWatcher()
453+
watcher.attach_loop(loop)
454+
policy.set_child_watcher(watcher)
449455
return loop
450456

451457

changes/2058.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add automatically a SafeChildWatcher to the test loop

tests/test_loop.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import asyncio
2+
import platform
3+
import threading
4+
5+
import pytest
6+
7+
8+
@pytest.mark.skipif(platform.system() == "Windows",
9+
reason="the test is not valid for Windows")
10+
@asyncio.coroutine
11+
def test_subprocess_co(loop):
12+
assert isinstance(threading.current_thread(), threading._MainThread)
13+
proc = yield from asyncio.create_subprocess_shell(
14+
"exit 0", loop=loop, stdin=asyncio.subprocess.DEVNULL,
15+
stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL)
16+
yield from proc.wait()

0 commit comments

Comments
 (0)