Issue #11743: Rewrite multiprocessing connection classes in pure Python.

This commit is contained in:
Antoine Pitrou 2011-05-09 17:04:27 +02:00
parent df77e3d4a0
commit 87cf220972
15 changed files with 490 additions and 983 deletions

View file

@ -44,7 +44,7 @@ import _multiprocessing
from multiprocessing import current_process
from multiprocessing.forking import Popen, duplicate, close, ForkingPickler
from multiprocessing.util import register_after_fork, debug, sub_debug
from multiprocessing.connection import Client, Listener
from multiprocessing.connection import Client, Listener, Connection
#
@ -159,7 +159,7 @@ def rebuild_handle(pickled_data):
return new_handle
#
# Register `_multiprocessing.Connection` with `ForkingPickler`
# Register `Connection` with `ForkingPickler`
#
def reduce_connection(conn):
@ -168,11 +168,11 @@ def reduce_connection(conn):
def rebuild_connection(reduced_handle, readable, writable):
handle = rebuild_handle(reduced_handle)
return _multiprocessing.Connection(
return Connection(
handle, readable=readable, writable=writable
)
ForkingPickler.register(_multiprocessing.Connection, reduce_connection)
ForkingPickler.register(Connection, reduce_connection)
#
# Register `socket.socket` with `ForkingPickler`
@ -201,6 +201,7 @@ ForkingPickler.register(socket.socket, reduce_socket)
#
if sys.platform == 'win32':
from multiprocessing.connection import PipeConnection
def reduce_pipe_connection(conn):
rh = reduce_handle(conn.fileno())
@ -208,8 +209,8 @@ if sys.platform == 'win32':
def rebuild_pipe_connection(reduced_handle, readable, writable):
handle = rebuild_handle(reduced_handle)
return _multiprocessing.PipeConnection(
return PipeConnection(
handle, readable=readable, writable=writable
)
ForkingPickler.register(_multiprocessing.PipeConnection, reduce_pipe_connection)
ForkingPickler.register(PipeConnection, reduce_pipe_connection)