Mercurial > cpython-lru_cache-weakref
annotate Lib/multiprocessing/reduction.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 7ea805d879e1 |
| children | d35f8e5b4197 |
| rev | line source |
|---|---|
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
1 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
2 # Module to allow connection and socket objects to be transferred |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
3 # between processes |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
4 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
5 # multiprocessing/reduction.py |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
6 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
7 # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
8 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
9 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
10 __all__ = [] |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
11 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
12 import os |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
13 import sys |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
14 import socket |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
15 import threading |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
16 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
17 import _multiprocessing |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
18 from multiprocessing import current_process |
|
47980
5f6dc2f86a88
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
Jesse Noller <jnoller@gmail.com>
parents:
47696
diff
changeset
|
19 from multiprocessing.forking import Popen, duplicate, close, ForkingPickler |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
20 from multiprocessing.util import register_after_fork, debug, sub_debug |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
21 from multiprocessing.connection import Client, Listener |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
22 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
23 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
24 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
25 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
26 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
27 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
28 if not(sys.platform == 'win32' or hasattr(_multiprocessing, 'recvfd')): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
29 raise ImportError('pickling of connections not supported') |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
30 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
31 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
32 # Platform specific definitions |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
33 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
34 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
35 if sys.platform == 'win32': |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
36 import _subprocess |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
37 from ._multiprocessing import win32 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
38 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
39 def send_handle(conn, handle, destination_pid): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
40 process_handle = win32.OpenProcess( |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
41 win32.PROCESS_ALL_ACCESS, False, destination_pid |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
42 ) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
43 try: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
44 new_handle = duplicate(handle, process_handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
45 conn.send(new_handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
46 finally: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
47 close(process_handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
48 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
49 def recv_handle(conn): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
50 return conn.recv() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
51 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
52 else: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
53 def send_handle(conn, handle, destination_pid): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
54 _multiprocessing.sendfd(conn.fileno(), handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
55 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
56 def recv_handle(conn): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
57 return _multiprocessing.recvfd(conn.fileno()) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
58 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
59 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
60 # Support for a per-process server thread which caches pickled handles |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
61 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
62 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
63 _cache = set() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
64 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
65 def _reset(obj): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
66 global _lock, _listener, _cache |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
67 for h in _cache: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
68 close(h) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
69 _cache.clear() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
70 _lock = threading.Lock() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
71 _listener = None |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
72 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
73 _reset(None) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
74 register_after_fork(_reset, _reset) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
75 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
76 def _get_listener(): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
77 global _listener |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
78 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
79 if _listener is None: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
80 _lock.acquire() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
81 try: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
82 if _listener is None: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
83 debug('starting listener and thread for sending handles') |
|
48302
7ea805d879e1
issue3352: clean up the multiprocessing API to remove many get_/set_ methods and convert them to properties. Update the docs and the examples included.
Jesse Noller <jnoller@gmail.com>
parents:
47980
diff
changeset
|
84 _listener = Listener(authkey=current_process().authkey) |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
85 t = threading.Thread(target=_serve) |
|
48302
7ea805d879e1
issue3352: clean up the multiprocessing API to remove many get_/set_ methods and convert them to properties. Update the docs and the examples included.
Jesse Noller <jnoller@gmail.com>
parents:
47980
diff
changeset
|
86 t.daemon = True |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
87 t.start() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
88 finally: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
89 _lock.release() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
90 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
91 return _listener |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
92 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
93 def _serve(): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
94 from .util import is_exiting, sub_warning |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
95 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
96 while 1: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
97 try: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
98 conn = _listener.accept() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
99 handle_wanted, destination_pid = conn.recv() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
100 _cache.remove(handle_wanted) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
101 send_handle(conn, handle_wanted, destination_pid) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
102 close(handle_wanted) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
103 conn.close() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
104 except: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
105 if not is_exiting(): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
106 import traceback |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
107 sub_warning( |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
108 'thread for sharing handles raised exception :\n' + |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
109 '-'*79 + '\n' + traceback.format_exc() + '-'*79 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
110 ) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
111 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
112 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
113 # Functions to be used for pickling/unpickling objects with handles |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
114 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
115 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
116 def reduce_handle(handle): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
117 if Popen.thread_is_spawning(): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
118 return (None, Popen.duplicate_for_child(handle), True) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
119 dup_handle = duplicate(handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
120 _cache.add(dup_handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
121 sub_debug('reducing handle %d', handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
122 return (_get_listener().address, dup_handle, False) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
123 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
124 def rebuild_handle(pickled_data): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
125 address, handle, inherited = pickled_data |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
126 if inherited: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
127 return handle |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
128 sub_debug('rebuilding handle %d', handle) |
|
48302
7ea805d879e1
issue3352: clean up the multiprocessing API to remove many get_/set_ methods and convert them to properties. Update the docs and the examples included.
Jesse Noller <jnoller@gmail.com>
parents:
47980
diff
changeset
|
129 conn = Client(address, authkey=current_process().authkey) |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
130 conn.send((handle, os.getpid())) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
131 new_handle = recv_handle(conn) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
132 conn.close() |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
133 return new_handle |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
134 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
135 # |
|
47980
5f6dc2f86a88
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
Jesse Noller <jnoller@gmail.com>
parents:
47696
diff
changeset
|
136 # Register `_multiprocessing.Connection` with `ForkingPickler` |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
137 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
138 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
139 def reduce_connection(conn): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
140 rh = reduce_handle(conn.fileno()) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
141 return rebuild_connection, (rh, conn.readable, conn.writable) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
142 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
143 def rebuild_connection(reduced_handle, readable, writable): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
144 handle = rebuild_handle(reduced_handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
145 return _multiprocessing.Connection( |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
146 handle, readable=readable, writable=writable |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
147 ) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
148 |
|
47980
5f6dc2f86a88
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
Jesse Noller <jnoller@gmail.com>
parents:
47696
diff
changeset
|
149 ForkingPickler.register(_multiprocessing.Connection, reduce_connection) |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
150 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
151 # |
|
47980
5f6dc2f86a88
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
Jesse Noller <jnoller@gmail.com>
parents:
47696
diff
changeset
|
152 # Register `socket.socket` with `ForkingPickler` |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
153 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
154 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
155 def fromfd(fd, family, type_, proto=0): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
156 s = socket.fromfd(fd, family, type_, proto) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
157 if s.__class__ is not socket.socket: |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
158 s = socket.socket(_sock=s) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
159 return s |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
160 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
161 def reduce_socket(s): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
162 reduced_handle = reduce_handle(s.fileno()) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
163 return rebuild_socket, (reduced_handle, s.family, s.type, s.proto) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
164 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
165 def rebuild_socket(reduced_handle, family, type_, proto): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
166 fd = rebuild_handle(reduced_handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
167 _sock = fromfd(fd, family, type_, proto) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
168 close(fd) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
169 return _sock |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
170 |
|
47980
5f6dc2f86a88
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
Jesse Noller <jnoller@gmail.com>
parents:
47696
diff
changeset
|
171 ForkingPickler.register(socket.socket, reduce_socket) |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
172 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
173 # |
|
47980
5f6dc2f86a88
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
Jesse Noller <jnoller@gmail.com>
parents:
47696
diff
changeset
|
174 # Register `_multiprocessing.PipeConnection` with `ForkingPickler` |
|
47696
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
175 # |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
176 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
177 if sys.platform == 'win32': |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
178 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
179 def reduce_pipe_connection(conn): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
180 rh = reduce_handle(conn.fileno()) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
181 return rebuild_pipe_connection, (rh, conn.readable, conn.writable) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
182 |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
183 def rebuild_pipe_connection(reduced_handle, readable, writable): |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
184 handle = rebuild_handle(reduced_handle) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
185 return _multiprocessing.PipeConnection( |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
186 handle, readable=readable, writable=writable |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
187 ) |
|
d01165fae98e
darn! I converted half of the files the wrong way.
Benjamin Peterson <benjamin@python.org>
parents:
47694
diff
changeset
|
188 |
|
47980
5f6dc2f86a88
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
Jesse Noller <jnoller@gmail.com>
parents:
47696
diff
changeset
|
189 ForkingPickler.register(_multiprocessing.PipeConnection, reduce_pipe_connection) |
