|
50 | 50 | from multiprocessing import current_process, AuthenticationError, BufferTooShort |
51 | 51 | from multiprocessing.util import ( |
52 | 52 | get_temp_dir, Finalize, sub_debug, debug, _eintr_retry) |
| 53 | +from multiprocessing.forking import ForkingPickler |
53 | 54 | try: |
54 | 55 | import _winapi |
55 | 56 | from _winapi import WAIT_OBJECT_0, WAIT_TIMEOUT, INFINITE |
@@ -227,8 +228,9 @@ def send(self, obj): |
227 | 228 | """Send a (picklable) object""" |
228 | 229 | self._check_closed() |
229 | 230 | self._check_writable() |
230 | | - buf = pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL) |
231 | | - self._send_bytes(memoryview(buf)) |
| 231 | + buf = io.BytesIO() |
| 232 | + ForkingPickler(buf, pickle.HIGHEST_PROTOCOL).dump(obj) |
| 233 | + self._send_bytes(buf.getbuffer()) |
232 | 234 |
|
233 | 235 | def recv_bytes(self, maxlength=None): |
234 | 236 | """ |
@@ -880,3 +882,21 @@ def wait(object_list, timeout=None): |
880 | 882 | raise |
881 | 883 | if timeout is not None: |
882 | 884 | timeout = deadline - time.time() |
| 885 | + |
| 886 | +# |
| 887 | +# Make connection and socket objects sharable if possible |
| 888 | +# |
| 889 | + |
| 890 | +if sys.platform == 'win32': |
| 891 | + from . import reduction |
| 892 | + ForkingPickler.register(socket.socket, reduction.reduce_socket) |
| 893 | + ForkingPickler.register(Connection, reduction.reduce_connection) |
| 894 | + ForkingPickler.register(PipeConnection, reduction.reduce_pipe_connection) |
| 895 | +else: |
| 896 | + try: |
| 897 | + from . import reduction |
| 898 | + except ImportError: |
| 899 | + pass |
| 900 | + else: |
| 901 | + ForkingPickler.register(socket.socket, reduction.reduce_socket) |
| 902 | + ForkingPickler.register(Connection, reduction.reduce_connection) |
0 commit comments