summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-10-05 21:01:01 (GMT)
committerYury Selivanov <yury@magic.io>2016-10-05 21:01:01 (GMT)
commit67ea61818ef9b435bd47270e0a87e768ebdeeae6 (patch)
tree0b6e88a25888b5d929f229b28e00c730dbda1b1a /Lib/asyncio
parent3ae41554c69b807659fab815ad5675bed5ae237e (diff)
parent9eb6c677763c1eaf0646170ccff110c89828a06e (diff)
downloadcpython-67ea61818ef9b435bd47270e0a87e768ebdeeae6.zip
cpython-67ea61818ef9b435bd47270e0a87e768ebdeeae6.tar.gz
cpython-67ea61818ef9b435bd47270e0a87e768ebdeeae6.tar.bz2
Merge 3.5 (issue #28368)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/unix_events.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 2b22dce..972a42d 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -748,6 +748,7 @@ class BaseChildWatcher(AbstractChildWatcher):
def __init__(self):
self._loop = None
+ self._callbacks = {}
def close(self):
self.attach_loop(None)
@@ -761,6 +762,12 @@ class BaseChildWatcher(AbstractChildWatcher):
def attach_loop(self, loop):
assert loop is None or isinstance(loop, events.AbstractEventLoop)
+ if self._loop is not None and loop is None and self._callbacks:
+ warnings.warn(
+ 'A loop is being detached '
+ 'from a child watcher with pending handlers',
+ RuntimeWarning)
+
if self._loop is not None:
self._loop.remove_signal_handler(signal.SIGCHLD)
@@ -809,10 +816,6 @@ class SafeChildWatcher(BaseChildWatcher):
big number of children (O(n) each time SIGCHLD is raised)
"""
- def __init__(self):
- super().__init__()
- self._callbacks = {}
-
def close(self):
self._callbacks.clear()
super().close()
@@ -824,6 +827,11 @@ class SafeChildWatcher(BaseChildWatcher):
pass
def add_child_handler(self, pid, callback, *args):
+ if self._loop is None:
+ raise RuntimeError(
+ "Cannot add child handler, "
+ "the child watcher does not have a loop attached")
+
self._callbacks[pid] = (callback, args)
# Prevent a race condition in case the child is already terminated.
@@ -888,7 +896,6 @@ class FastChildWatcher(BaseChildWatcher):
"""
def __init__(self):
super().__init__()
- self._callbacks = {}
self._lock = threading.Lock()
self._zombies = {}
self._forks = 0
@@ -920,6 +927,12 @@ class FastChildWatcher(BaseChildWatcher):
def add_child_handler(self, pid, callback, *args):
assert self._forks, "Must use the context manager"
+
+ if self._loop is None:
+ raise RuntimeError(
+ "Cannot add child handler, "
+ "the child watcher does not have a loop attached")
+
with self._lock:
try:
returncode = self._zombies.pop(pid)