summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing/pool.py
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2013-10-16 15:41:56 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2013-10-16 15:41:56 (GMT)
commitb1694cf588ca915c003b9b79c9fdeab82deb9476 (patch)
tree923f376dd771dbc25815cad0708c753ef3af3b14 /Lib/multiprocessing/pool.py
parent3e4b52875e0162b536817da93f54b1988195c3ab (diff)
downloadcpython-b1694cf588ca915c003b9b79c9fdeab82deb9476.zip
cpython-b1694cf588ca915c003b9b79c9fdeab82deb9476.tar.gz
cpython-b1694cf588ca915c003b9b79c9fdeab82deb9476.tar.bz2
Issue #18999: Make multiprocessing use context objects.
This allows different parts of a program to use different methods for starting processes without interfering with each other.
Diffstat (limited to 'Lib/multiprocessing/pool.py')
-rw-r--r--Lib/multiprocessing/pool.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index 1cecd09..4be00d5 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -24,7 +24,7 @@ import traceback
# If threading is available then ThreadPool should be provided. Therefore
# we avoid top-level imports which are liable to fail on some systems.
from . import util
-from . import Process, cpu_count, TimeoutError, SimpleQueue
+from . import get_context, cpu_count, TimeoutError
#
# Constants representing the state of a pool
@@ -137,10 +137,12 @@ class Pool(object):
'''
Class which supports an async version of applying functions to arguments.
'''
- Process = Process
+ def Process(self, *args, **kwds):
+ return self._ctx.Process(*args, **kwds)
def __init__(self, processes=None, initializer=None, initargs=(),
- maxtasksperchild=None):
+ maxtasksperchild=None, context=None):
+ self._ctx = context or get_context()
self._setup_queues()
self._taskqueue = queue.Queue()
self._cache = {}
@@ -232,8 +234,8 @@ class Pool(object):
self._repopulate_pool()
def _setup_queues(self):
- self._inqueue = SimpleQueue()
- self._outqueue = SimpleQueue()
+ self._inqueue = self._ctx.SimpleQueue()
+ self._outqueue = self._ctx.SimpleQueue()
self._quick_put = self._inqueue._writer.send
self._quick_get = self._outqueue._reader.recv