diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2013-10-16 15:41:56 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2013-10-16 15:41:56 (GMT) |
commit | b1694cf588ca915c003b9b79c9fdeab82deb9476 (patch) | |
tree | 923f376dd771dbc25815cad0708c753ef3af3b14 /Lib/multiprocessing/managers.py | |
parent | 3e4b52875e0162b536817da93f54b1988195c3ab (diff) | |
download | cpython-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/managers.py')
-rw-r--r-- | Lib/multiprocessing/managers.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py index f580e9e..cc87d36 100644 --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -23,11 +23,12 @@ from time import time as _time from traceback import format_exc from . import connection +from . import context from . import pool from . import process -from . import popen from . import reduction from . import util +from . import get_context # # Register some things for pickling @@ -438,7 +439,8 @@ class BaseManager(object): _registry = {} _Server = Server - def __init__(self, address=None, authkey=None, serializer='pickle'): + def __init__(self, address=None, authkey=None, serializer='pickle', + ctx=None): if authkey is None: authkey = process.current_process().authkey self._address = address # XXX not final address if eg ('', 0) @@ -447,6 +449,7 @@ class BaseManager(object): self._state.value = State.INITIAL self._serializer = serializer self._Listener, self._Client = listener_client[serializer] + self._ctx = ctx or get_context() def get_server(self): ''' @@ -478,7 +481,7 @@ class BaseManager(object): reader, writer = connection.Pipe(duplex=False) # spawn process which runs a server - self._process = process.Process( + self._process = self._ctx.Process( target=type(self)._run_server, args=(self._registry, self._address, self._authkey, self._serializer, writer, initializer, initargs), @@ -800,7 +803,7 @@ class BaseProxy(object): def __reduce__(self): kwds = {} - if popen.get_spawning_popen() is not None: + if context.get_spawning_popen() is not None: kwds['authkey'] = self._authkey if getattr(self, '_isauto', False): |