diff -r c26e6beb2e35 Lib/asyncio/test_utils.py --- a/Lib/asyncio/test_utils.py Sat Jul 26 19:53:38 2014 +0300 +++ b/Lib/asyncio/test_utils.py Sat Jul 26 14:18:36 2014 -0400 @@ -14,6 +14,7 @@ import time import unittest from unittest import mock +from multiprocessing import current_process from http.server import HTTPServer from wsgiref.simple_server import WSGIRequestHandler, WSGIServer @@ -282,6 +283,7 @@ self._clock_resolution = 1e-9 self._timers = [] self._selector = TestSelector() + self._pid = current_process().pid self.readers = {} self.writers = {} diff -r c26e6beb2e35 Lib/asyncio/unix_events.py --- a/Lib/asyncio/unix_events.py Sat Jul 26 19:53:38 2014 +0300 +++ b/Lib/asyncio/unix_events.py Sat Jul 26 14:18:36 2014 -0400 @@ -9,6 +9,7 @@ import subprocess import sys import threading +from multiprocessing import current_process from . import base_events @@ -45,6 +46,7 @@ def __init__(self, selector=None): super().__init__(selector) self._signal_handlers = {} + self._pid = current_process().pid def _socketpair(self): return socket.socketpair() @@ -886,6 +888,15 @@ isinstance(threading.current_thread(), threading._MainThread): self._watcher.attach_loop(loop) + def get_event_loop(self): + # Get a new loop object if we're in a mp child process. + if (self._local._loop is not None and + self._local._loop._pid != current_process().pid): + self.set_event_loop(self.new_event_loop()) + return self._local._loop + else: + return super().get_event_loop() + def get_child_watcher(self): """Get the watcher for child processes. diff -r c26e6beb2e35 Lib/test/test_asyncio/test_base_events.py --- a/Lib/test/test_asyncio/test_base_events.py Sat Jul 26 19:53:38 2014 +0300 +++ b/Lib/test/test_asyncio/test_base_events.py Sat Jul 26 14:18:36 2014 -0400 @@ -6,6 +6,7 @@ import sys import time import unittest +from multiprocessing import current_process from unittest import mock from test.script_helper import assert_python_ok from test.support import IPV6_ENABLED @@ -156,6 +157,7 @@ other_loop = base_events.BaseEventLoop() other_loop._selector = mock.Mock() + other_loop._pid = current_process().pid asyncio.set_event_loop(other_loop) # raise RuntimeError if the event loop is different in debug mode