| 1 |
cp -rf py3.13/examples . |
| 2 |
cp -rf py3.13/doc . |
| 3 |
cp -f py3.13/index.html . |
| 4 |
cp -rf py3.13/_multiprocess _multiprocess |
| 5 |
cp -rf Python-3.14.0a1/Modules/_multiprocessing Modules/_multiprocess |
| 6 |
cp -rf py3.13/multiprocess multiprocess |
| 7 |
# ---------------------------------------------------------------------- |
| 8 |
$ diff Python-3.14.0a1/Modules/_multiprocessing/semaphore.c Modules/_multiprocess/semaphore.c |
| 9 |
10c10 |
| 10 |
< #include "multiprocessing.h" |
| 11 |
--- |
| 12 |
> #include "multiprocess.h" |
| 13 |
39,40c39,40 |
| 14 |
< module _multiprocessing |
| 15 |
< class _multiprocessing.SemLock "SemLockObject *" "&_PyMp_SemLockType" |
| 16 |
--- |
| 17 |
> module _multiprocess |
| 18 |
> class _multiprocess.SemLock "SemLockObject *" "&_PyMp_SemLockType" |
| 19 |
85c85 |
| 20 |
< _multiprocessing.SemLock.acquire |
| 21 |
--- |
| 22 |
> _multiprocess.SemLock.acquire |
| 23 |
94,95c94,95 |
| 24 |
< _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 25 |
< PyObject *timeout_obj) |
| 26 |
--- |
| 27 |
> _multiprocess_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 28 |
> PyObject *timeout_obj) |
| 29 |
177c177 |
| 30 |
< _multiprocessing.SemLock.release |
| 31 |
--- |
| 32 |
> _multiprocess.SemLock.release |
| 33 |
183c183 |
| 34 |
< _multiprocessing_SemLock_release_impl(SemLockObject *self) |
| 35 |
--- |
| 36 |
> _multiprocess_SemLock_release_impl(SemLockObject *self) |
| 37 |
303c303 |
| 38 |
< _multiprocessing.SemLock.acquire |
| 39 |
--- |
| 40 |
> _multiprocess.SemLock.acquire |
| 41 |
312,313c312,313 |
| 42 |
< _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 43 |
< PyObject *timeout_obj) |
| 44 |
--- |
| 45 |
> _multiprocess_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 46 |
> PyObject *timeout_obj) |
| 47 |
389c389 |
| 48 |
< _multiprocessing.SemLock.release |
| 49 |
--- |
| 50 |
> _multiprocess.SemLock.release |
| 51 |
395c395 |
| 52 |
< _multiprocessing_SemLock_release_impl(SemLockObject *self) |
| 53 |
--- |
| 54 |
> _multiprocess_SemLock_release_impl(SemLockObject *self) |
| 55 |
479c479 |
| 56 |
< _multiprocessing.SemLock.__new__ |
| 57 |
--- |
| 58 |
> _multiprocess.SemLock.__new__ |
| 59 |
490,491c490,491 |
| 60 |
< _multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value, |
| 61 |
< int maxvalue, const char *name, int unlink) |
| 62 |
--- |
| 63 |
> _multiprocess_SemLock_impl(PyTypeObject *type, int kind, int value, |
| 64 |
> int maxvalue, const char *name, int unlink) |
| 65 |
538c538 |
| 66 |
< _multiprocessing.SemLock._rebuild |
| 67 |
--- |
| 68 |
> _multiprocess.SemLock._rebuild |
| 69 |
549,551c549,551 |
| 70 |
< _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle, |
| 71 |
< int kind, int maxvalue, |
| 72 |
< const char *name) |
| 73 |
--- |
| 74 |
> _multiprocess_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle, |
| 75 |
> int kind, int maxvalue, |
| 76 |
> const char *name) |
| 77 |
591c591 |
| 78 |
< _multiprocessing.SemLock._count |
| 79 |
--- |
| 80 |
> _multiprocess.SemLock._count |
| 81 |
597c597 |
| 82 |
< _multiprocessing_SemLock__count_impl(SemLockObject *self) |
| 83 |
--- |
| 84 |
> _multiprocess_SemLock__count_impl(SemLockObject *self) |
| 85 |
604c604 |
| 86 |
< _multiprocessing.SemLock._is_mine |
| 87 |
--- |
| 88 |
> _multiprocess.SemLock._is_mine |
| 89 |
610c610 |
| 90 |
< _multiprocessing_SemLock__is_mine_impl(SemLockObject *self) |
| 91 |
--- |
| 92 |
> _multiprocess_SemLock__is_mine_impl(SemLockObject *self) |
| 93 |
618c618 |
| 94 |
< _multiprocessing.SemLock._get_value |
| 95 |
--- |
| 96 |
> _multiprocess.SemLock._get_value |
| 97 |
624c624 |
| 98 |
< _multiprocessing_SemLock__get_value_impl(SemLockObject *self) |
| 99 |
--- |
| 100 |
> _multiprocess_SemLock__get_value_impl(SemLockObject *self) |
| 101 |
643c643 |
| 102 |
< _multiprocessing.SemLock._is_zero |
| 103 |
--- |
| 104 |
> _multiprocess.SemLock._is_zero |
| 105 |
649c649 |
| 106 |
< _multiprocessing_SemLock__is_zero_impl(SemLockObject *self) |
| 107 |
--- |
| 108 |
> _multiprocess_SemLock__is_zero_impl(SemLockObject *self) |
| 109 |
671c671 |
| 110 |
< _multiprocessing.SemLock._after_fork |
| 111 |
--- |
| 112 |
> _multiprocess.SemLock._after_fork |
| 113 |
677c677 |
| 114 |
< _multiprocessing_SemLock__after_fork_impl(SemLockObject *self) |
| 115 |
--- |
| 116 |
> _multiprocess_SemLock__after_fork_impl(SemLockObject *self) |
| 117 |
686c686 |
| 118 |
< _multiprocessing.SemLock.__enter__ |
| 119 |
--- |
| 120 |
> _multiprocess.SemLock.__enter__ |
| 121 |
692c692 |
| 122 |
< _multiprocessing_SemLock___enter___impl(SemLockObject *self) |
| 123 |
--- |
| 124 |
> _multiprocess_SemLock___enter___impl(SemLockObject *self) |
| 125 |
695c695 |
| 126 |
< return _multiprocessing_SemLock_acquire_impl(self, 1, Py_None); |
| 127 |
--- |
| 128 |
> return _multiprocess_SemLock_acquire_impl(self, 1, Py_None); |
| 129 |
700c700 |
| 130 |
< _multiprocessing.SemLock.__exit__ |
| 131 |
--- |
| 132 |
> _multiprocess.SemLock.__exit__ |
| 133 |
711,713c711,713 |
| 134 |
< _multiprocessing_SemLock___exit___impl(SemLockObject *self, |
| 135 |
< PyObject *exc_type, |
| 136 |
< PyObject *exc_value, PyObject *exc_tb) |
| 137 |
--- |
| 138 |
> _multiprocess_SemLock___exit___impl(SemLockObject *self, |
| 139 |
> PyObject *exc_type, |
| 140 |
> PyObject *exc_value, PyObject *exc_tb) |
| 141 |
716c716 |
| 142 |
< return _multiprocessing_SemLock_release_impl(self); |
| 143 |
--- |
| 144 |
> return _multiprocess_SemLock_release_impl(self); |
| 145 |
731,740c731,740 |
| 146 |
< _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF |
| 147 |
< _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF |
| 148 |
< _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF |
| 149 |
< _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF |
| 150 |
< _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF |
| 151 |
< _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF |
| 152 |
< _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF |
| 153 |
< _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF |
| 154 |
< _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF |
| 155 |
< _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF |
| 156 |
--- |
| 157 |
> _MULTIPROCESS_SEMLOCK_ACQUIRE_METHODDEF |
| 158 |
> _MULTIPROCESS_SEMLOCK_RELEASE_METHODDEF |
| 159 |
> _MULTIPROCESS_SEMLOCK___ENTER___METHODDEF |
| 160 |
> _MULTIPROCESS_SEMLOCK___EXIT___METHODDEF |
| 161 |
> _MULTIPROCESS_SEMLOCK__COUNT_METHODDEF |
| 162 |
> _MULTIPROCESS_SEMLOCK__IS_MINE_METHODDEF |
| 163 |
> _MULTIPROCESS_SEMLOCK__GET_VALUE_METHODDEF |
| 164 |
> _MULTIPROCESS_SEMLOCK__IS_ZERO_METHODDEF |
| 165 |
> _MULTIPROCESS_SEMLOCK__REBUILD_METHODDEF |
| 166 |
> _MULTIPROCESS_SEMLOCK__AFTER_FORK_METHODDEF |
| 167 |
771c771 |
| 168 |
< {Py_tp_new, _multiprocessing_SemLock}, |
| 169 |
--- |
| 170 |
> {Py_tp_new, _multiprocess_SemLock}, |
| 171 |
779c779 |
| 172 |
< .name = "_multiprocessing.SemLock", |
| 173 |
--- |
| 174 |
> .name = "_multiprocess.SemLock", |
| 175 |
$ diff Python-3.14.0a1/Modules/_multiprocessing/multiprocessing.h Modules/_multiprocess/multiprocess.h |
| 176 |
1,2c1,2 |
| 177 |
< #ifndef MULTIPROCESSING_H |
| 178 |
< #define MULTIPROCESSING_H |
| 179 |
--- |
| 180 |
> #ifndef MULTIPROCESS_H |
| 181 |
> #define MULTIPROCESS_H |
| 182 |
104c104 |
| 183 |
< #endif /* MULTIPROCESSING_H */ |
| 184 |
--- |
| 185 |
> #endif /* MULTIPROCESS_H */ |
| 186 |
$ diff Python-3.14.0a1/Modules/_multiprocessing/multiprocessing.c Modules/_multiprocess/multiprocess.c |
| 187 |
2c2 |
| 188 |
< * Extension module used by multiprocessing package |
| 189 |
--- |
| 190 |
> * Extension module used by multiprocess package |
| 191 |
4c4 |
| 192 |
< * multiprocessing.c |
| 193 |
--- |
| 194 |
> * multiprocess.c |
| 195 |
10c10 |
| 196 |
< #include "multiprocessing.h" |
| 197 |
--- |
| 198 |
> #include "multiprocess.h" |
| 199 |
30c30 |
| 200 |
< module _multiprocessing |
| 201 |
--- |
| 202 |
> module _multiprocess |
| 203 |
77c77 |
| 204 |
< _multiprocessing.closesocket |
| 205 |
--- |
| 206 |
> _multiprocess.closesocket |
| 207 |
85c85 |
| 208 |
< _multiprocessing_closesocket_impl(PyObject *module, HANDLE handle) |
| 209 |
--- |
| 210 |
> _multiprocess_closesocket_impl(PyObject *module, HANDLE handle) |
| 211 |
100c100 |
| 212 |
< _multiprocessing.recv |
| 213 |
--- |
| 214 |
> _multiprocess.recv |
| 215 |
109c109 |
| 216 |
< _multiprocessing_recv_impl(PyObject *module, HANDLE handle, int size) |
| 217 |
--- |
| 218 |
> _multiprocess_recv_impl(PyObject *module, HANDLE handle, int size) |
| 219 |
132c132 |
| 220 |
< _multiprocessing.send |
| 221 |
--- |
| 222 |
> _multiprocess.send |
| 223 |
141c141 |
| 224 |
< _multiprocessing_send_impl(PyObject *module, HANDLE handle, Py_buffer *buf) |
| 225 |
--- |
| 226 |
> _multiprocess_send_impl(PyObject *module, HANDLE handle, Py_buffer *buf) |
| 227 |
160c160 |
| 228 |
< _multiprocessing.sem_unlink |
| 229 |
--- |
| 230 |
> _multiprocess.sem_unlink |
| 231 |
168c168 |
| 232 |
< _multiprocessing_sem_unlink_impl(PyObject *module, const char *name) |
| 233 |
--- |
| 234 |
> _multiprocess_sem_unlink_impl(PyObject *module, const char *name) |
| 235 |
180,182c180,182 |
| 236 |
< _MULTIPROCESSING_CLOSESOCKET_METHODDEF |
| 237 |
< _MULTIPROCESSING_RECV_METHODDEF |
| 238 |
< _MULTIPROCESSING_SEND_METHODDEF |
| 239 |
--- |
| 240 |
> _MULTIPROCESS_CLOSESOCKET_METHODDEF |
| 241 |
> _MULTIPROCESS_RECV_METHODDEF |
| 242 |
> _MULTIPROCESS_SEND_METHODDEF |
| 243 |
185c185 |
| 244 |
< _MULTIPROCESSING_SEM_UNLINK_METHODDEF |
| 245 |
--- |
| 246 |
> _MULTIPROCESS_SEM_UNLINK_METHODDEF |
| 247 |
196c196 |
| 248 |
< multiprocessing_exec(PyObject *module) |
| 249 |
--- |
| 250 |
> multiprocess_exec(PyObject *module) |
| 251 |
277,278c277,278 |
| 252 |
< static PyModuleDef_Slot multiprocessing_slots[] = { |
| 253 |
< {Py_mod_exec, multiprocessing_exec}, |
| 254 |
--- |
| 255 |
> static PyModuleDef_Slot multiprocess_slots[] = { |
| 256 |
> {Py_mod_exec, multiprocess_exec}, |
| 257 |
284c284 |
| 258 |
< static struct PyModuleDef multiprocessing_module = { |
| 259 |
--- |
| 260 |
> static struct PyModuleDef multiprocess_module = { |
| 261 |
286c286 |
| 262 |
< .m_name = "_multiprocessing", |
| 263 |
--- |
| 264 |
> .m_name = "_multiprocess", |
| 265 |
289c289 |
| 266 |
< .m_slots = multiprocessing_slots, |
| 267 |
--- |
| 268 |
> .m_slots = multiprocess_slots, |
| 269 |
293c293 |
| 270 |
< PyInit__multiprocessing(void) |
| 271 |
--- |
| 272 |
> PyInit__multiprocess(void) |
| 273 |
295c295 |
| 274 |
< return PyModuleDef_Init(&multiprocessing_module); |
| 275 |
--- |
| 276 |
> return PyModuleDef_Init(&multiprocess_module); |
| 277 |
# ---------------------------------------------------------------------- |
| 278 |
diff Python-3.13.0rc1/Lib/multiprocessing/connection.py Python-3.14.0a1/Lib/multiprocessing/connection.py |
| 279 |
13a14 |
| 280 |
> import itertools |
| 281 |
18d18 |
| 282 |
< import time |
| 283 |
20c20 |
| 284 |
< import itertools |
| 285 |
--- |
| 286 |
> import time |
| 287 |
42c42,44 |
| 288 |
< BUFSIZE = 8192 |
| 289 |
--- |
| 290 |
> # 64 KiB is the default PIPE buffer size of most POSIX platforms. |
| 291 |
> BUFSIZE = 64 * 1024 |
| 292 |
> |
| 293 |
395c397,398 |
| 294 |
< chunk = read(handle, remaining) |
| 295 |
--- |
| 296 |
> to_read = min(BUFSIZE, remaining) |
| 297 |
> chunk = read(handle, to_read) |
| 298 |
diff Python-3.13.0rc1/Lib/multiprocessing/context.py Python-3.14.0a1/Lib/multiprocessing/context.py |
| 299 |
170c170 |
| 300 |
< from . import connection |
| 301 |
--- |
| 302 |
> from . import connection # noqa: F401 |
| 303 |
262,268c262,267 |
| 304 |
< if sys.platform == 'win32': |
| 305 |
< return ['spawn'] |
| 306 |
< else: |
| 307 |
< methods = ['spawn', 'fork'] if sys.platform == 'darwin' else ['fork', 'spawn'] |
| 308 |
< if reduction.HAVE_SEND_HANDLE: |
| 309 |
< methods.append('forkserver') |
| 310 |
< return methods |
| 311 |
--- |
| 312 |
> default = self._default_context.get_start_method() |
| 313 |
> start_method_names = [default] |
| 314 |
> start_method_names.extend( |
| 315 |
> name for name in _concrete_contexts if name != default |
| 316 |
> ) |
| 317 |
> return start_method_names |
| 318 |
323,326c322,326 |
| 319 |
< if sys.platform == 'darwin': |
| 320 |
< # bpo-33725: running arbitrary code after fork() is no longer reliable |
| 321 |
< # on macOS since macOS 10.14 (Mojave). Use spawn by default instead. |
| 322 |
< _default_context = DefaultContext(_concrete_contexts['spawn']) |
| 323 |
--- |
| 324 |
> # bpo-33725: running arbitrary code after fork() is no longer reliable |
| 325 |
> # on macOS since macOS 10.14 (Mojave). Use spawn by default instead. |
| 326 |
> # gh-84559: We changed everyones default to a thread safeish one in 3.14. |
| 327 |
> if reduction.HAVE_SEND_HANDLE and sys.platform != 'darwin': |
| 328 |
> _default_context = DefaultContext(_concrete_contexts['forkserver']) |
| 329 |
328c328 |
| 330 |
< _default_context = DefaultContext(_concrete_contexts['fork']) |
| 331 |
--- |
| 332 |
> _default_context = DefaultContext(_concrete_contexts['spawn']) |
| 333 |
330c330 |
| 334 |
< else: |
| 335 |
--- |
| 336 |
> else: # Windows |
| 337 |
diff Python-3.13.0rc1/Lib/multiprocessing/managers.py Python-3.14.0a1/Lib/multiprocessing/managers.py |
| 338 |
1155,1158c1155,1158 |
| 339 |
< '__add__', '__contains__', '__delitem__', '__getitem__', '__len__', |
| 340 |
< '__mul__', '__reversed__', '__rmul__', '__setitem__', |
| 341 |
< 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', |
| 342 |
< 'reverse', 'sort', '__imul__' |
| 343 |
--- |
| 344 |
> '__add__', '__contains__', '__delitem__', '__getitem__', '__imul__', |
| 345 |
> '__len__', '__mul__', '__reversed__', '__rmul__', '__setitem__', |
| 346 |
> 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', |
| 347 |
> 'remove', 'reverse', 'sort', |
| 348 |
1172,1173c1172,1174 |
| 349 |
< '__contains__', '__delitem__', '__getitem__', '__iter__', '__len__', |
| 350 |
< '__setitem__', 'clear', 'copy', 'get', 'items', |
| 351 |
--- |
| 352 |
> '__contains__', '__delitem__', '__getitem__', '__ior__', '__iter__', |
| 353 |
> '__len__', '__or__', '__reversed__', '__ror__', |
| 354 |
> '__setitem__', 'clear', 'copy', 'fromkeys', 'get', 'items', |
| 355 |
1180c1181,1183 |
| 356 |
< __class_getitem__ = classmethod(types.GenericAlias) |
| 357 |
--- |
| 358 |
> def __ior__(self, value): |
| 359 |
> self._callmethod('__ior__', (value,)) |
| 360 |
> return self |
| 361 |
1181a1185 |
| 362 |
> __class_getitem__ = classmethod(types.GenericAlias) |
| 363 |
diff Python-3.13.0rc1/Lib/multiprocessing/shared_memory.py Python-3.14.0a1/Lib/multiprocessing/shared_memory.py |
| 364 |
542c542 |
| 365 |
< raise ValueError(f"{value!r} not in this container") |
| 366 |
--- |
| 367 |
> raise ValueError("ShareableList.index(x): x not in list") |
| 368 |
diff Python-3.13.0rc1/Lib/multiprocessing/util.py Python-3.14.0a1/Lib/multiprocessing/util.py |
| 369 |
17c17 |
| 370 |
< from subprocess import _args_from_interpreter_flags |
| 371 |
--- |
| 372 |
> from subprocess import _args_from_interpreter_flags # noqa: F401 |
| 373 |
448,449c448 |
| 374 |
< False, False, -1, None, None, None, -1, None, |
| 375 |
< subprocess._USE_VFORK) |
| 376 |
--- |
| 377 |
> False, False, -1, None, None, None, -1, None) |
| 378 |
$ diff Python-3.13.0rc1/Lib/test/_test_multiprocessing.py Python-3.14.0a1/Lib/test/_test_multiprocessing.py |
| 379 |
5556c5556 |
| 380 |
< def test_get_all(self): |
| 381 |
--- |
| 382 |
> def test_get_all_start_methods(self): |
| 383 |
5557a5558 |
| 384 |
> self.assertIn('spawn', methods) |
| 385 |
5559a5561,5565 |
| 386 |
> elif sys.platform == 'darwin': |
| 387 |
> self.assertEqual(methods[0], 'spawn') # The default is first. |
| 388 |
> # Whether these work or not, they remain available on macOS. |
| 389 |
> self.assertIn('fork', methods) |
| 390 |
> self.assertIn('forkserver', methods) |
| 391 |
5561,5564c5567,5578 |
| 392 |
< self.assertTrue(methods == ['fork', 'spawn'] or |
| 393 |
< methods == ['spawn', 'fork'] or |
| 394 |
< methods == ['fork', 'spawn', 'forkserver'] or |
| 395 |
< methods == ['spawn', 'fork', 'forkserver']) |
| 396 |
--- |
| 397 |
> # POSIX |
| 398 |
> self.assertIn('fork', methods) |
| 399 |
> if other_methods := set(methods) - {'fork', 'spawn'}: |
| 400 |
> # If there are more than those two, forkserver must be one. |
| 401 |
> self.assertEqual({'forkserver'}, other_methods) |
| 402 |
> # The default is the first method in the list. |
| 403 |
> self.assertIn(methods[0], {'forkserver', 'spawn'}, |
| 404 |
> msg='3.14+ default must not be fork') |
| 405 |
> if methods[0] == 'spawn': |
| 406 |
> # Confirm that the current default selection logic prefers |
| 407 |
> # forkserver vs spawn when available. |
| 408 |
> self.assertNotIn('forkserver', methods) |
| 409 |
6092a6107,6122 |
| 410 |
> obj += [7] |
| 411 |
> case.assertIsInstance(obj, multiprocessing.managers.ListProxy) |
| 412 |
> case.assertListEqual(list(obj), [5, 7]) |
| 413 |
> obj *= 2 |
| 414 |
> case.assertIsInstance(obj, multiprocessing.managers.ListProxy) |
| 415 |
> case.assertListEqual(list(obj), [5, 7, 5, 7]) |
| 416 |
> double_obj = obj * 2 |
| 417 |
> case.assertIsInstance(double_obj, list) |
| 418 |
> case.assertListEqual(list(double_obj), [5, 7, 5, 7, 5, 7, 5, 7]) |
| 419 |
> double_obj = 2 * obj |
| 420 |
> case.assertIsInstance(double_obj, list) |
| 421 |
> case.assertListEqual(list(double_obj), [5, 7, 5, 7, 5, 7, 5, 7]) |
| 422 |
> copied_obj = obj.copy() |
| 423 |
> case.assertIsInstance(copied_obj, list) |
| 424 |
> case.assertListEqual(list(copied_obj), [5, 7, 5, 7]) |
| 425 |
> obj.extend(double_obj + copied_obj) |
| 426 |
6097,6098c6127,6130 |
| 427 |
< case.assertEqual(len(obj), 1) |
| 428 |
< case.assertEqual(obj.pop(0), 5) |
| 429 |
--- |
| 430 |
> case.assertEqual(len(obj), 16) |
| 431 |
> case.assertEqual(obj.pop(0), 7) |
| 432 |
> obj.clear() |
| 433 |
> case.assertEqual(len(obj), 0) |
| 434 |
6117c6149,6171 |
| 435 |
< case.assertTupleEqual(obj.popitem(), ('foo', 5)) |
| 436 |
--- |
| 437 |
> obj |= {'bar': 6} |
| 438 |
> case.assertIsInstance(obj, multiprocessing.managers.DictProxy) |
| 439 |
> case.assertDictEqual(dict(obj), {'foo': 5, 'bar': 6}) |
| 440 |
> x = reversed(obj) |
| 441 |
> case.assertIsInstance(x, type(iter([]))) |
| 442 |
> case.assertListEqual(list(x), ['bar', 'foo']) |
| 443 |
> x = {'bar': 7, 'baz': 7} | obj |
| 444 |
> case.assertIsInstance(x, dict) |
| 445 |
> case.assertDictEqual(dict(x), {'foo': 5, 'bar': 6, 'baz': 7}) |
| 446 |
> x = obj | {'bar': 7, 'baz': 7} |
| 447 |
> case.assertIsInstance(x, dict) |
| 448 |
> case.assertDictEqual(dict(x), {'foo': 5, 'bar': 7, 'baz': 7}) |
| 449 |
> x = obj.fromkeys(['bar'], 6) |
| 450 |
> case.assertIsInstance(x, dict) |
| 451 |
> case.assertDictEqual(x, {'bar': 6}) |
| 452 |
> x = obj.popitem() |
| 453 |
> case.assertIsInstance(x, tuple) |
| 454 |
> case.assertTupleEqual(x, ('bar', 6)) |
| 455 |
> obj.setdefault('bar', 0) |
| 456 |
> obj.update({'bar': 7}) |
| 457 |
> case.assertEqual(obj.pop('bar'), 7) |
| 458 |
> obj.clear() |
| 459 |
> case.assertEqual(len(obj), 0) |
| 460 |
|
| 461 |
# ---------------------------------------------------------------------- |
| 462 |
diff Python-3.14.0a1/Modules/_multiprocessing/semaphore.c Python-3.14.0a2/Modules/_multiprocessing/semaphore.c |
| 463 |
17a18 |
| 464 |
> // These match the values in Lib/multiprocessing/synchronize.py |
| 465 |
diff Python-3.14.0a1/Modules/_multiprocessing/clinic/semaphore.c.h Python-3.14.0a2/Modules/_multiprocessing/clinic/semaphore.c.h |
| 466 |
61c61,62 |
| 467 |
< args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); |
| 468 |
--- |
| 469 |
> args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 470 |
> /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 471 |
166c167,168 |
| 472 |
< args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); |
| 473 |
--- |
| 474 |
> args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 475 |
> /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 476 |
266c268,269 |
| 477 |
< fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 5, 5, 0, argsbuf); |
| 478 |
--- |
| 479 |
> fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
| 480 |
> /*minpos*/ 5, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 481 |
576c579 |
| 482 |
< /*[clinic end generated code: output=dea36482d23a355f input=a9049054013a1b77]*/ |
| 483 |
--- |
| 484 |
> /*[clinic end generated code: output=9023d3e48a24afd2 input=a9049054013a1b77]*/ |
| 485 |
diff Python-3.14.0a1/Lib/multiprocessing/forkserver.py Python-3.14.0a2/Lib/multiprocessing/forkserver.py |
| 486 |
170a171,172 |
| 487 |
> if sys_path is not None: |
| 488 |
> sys.path[:] = sys_path |
| 489 |
diff Python-3.14.0a1/Lib/multiprocessing/managers.py Python-3.14.0a2/Lib/multiprocessing/managers.py |
| 490 |
20a21 |
| 491 |
> import collections.abc |
| 492 |
760a762,765 |
| 493 |
> # Each instance gets a `_serial` number. Unlike `id(...)`, this number |
| 494 |
> # is never reused. |
| 495 |
> _next_serial = 1 |
| 496 |
> |
| 497 |
764,767c769,775 |
| 498 |
< tls_idset = BaseProxy._address_to_local.get(token.address, None) |
| 499 |
< if tls_idset is None: |
| 500 |
< tls_idset = util.ForkAwareLocal(), ProcessLocalSet() |
| 501 |
< BaseProxy._address_to_local[token.address] = tls_idset |
| 502 |
--- |
| 503 |
> tls_serials = BaseProxy._address_to_local.get(token.address, None) |
| 504 |
> if tls_serials is None: |
| 505 |
> tls_serials = util.ForkAwareLocal(), ProcessLocalSet() |
| 506 |
> BaseProxy._address_to_local[token.address] = tls_serials |
| 507 |
> |
| 508 |
> self._serial = BaseProxy._next_serial |
| 509 |
> BaseProxy._next_serial += 1 |
| 510 |
771c779 |
| 511 |
< self._tls = tls_idset[0] |
| 512 |
--- |
| 513 |
> self._tls = tls_serials[0] |
| 514 |
773,774c781,782 |
| 515 |
< # self._idset is used to record the identities of all shared |
| 516 |
< # objects for which the current process owns references and |
| 517 |
--- |
| 518 |
> # self._all_serials is a set used to record the identities of all |
| 519 |
> # shared objects for which the current process owns references and |
| 520 |
776c784 |
| 521 |
< self._idset = tls_idset[1] |
| 522 |
--- |
| 523 |
> self._all_serials = tls_serials[1] |
| 524 |
859c867 |
| 525 |
< self._idset.add(self._id) |
| 526 |
--- |
| 527 |
> self._all_serials.add(self._serial) |
| 528 |
865,866c873,874 |
| 529 |
< args=(self._token, self._authkey, state, |
| 530 |
< self._tls, self._idset, self._Client), |
| 531 |
--- |
| 532 |
> args=(self._token, self._serial, self._authkey, state, |
| 533 |
> self._tls, self._all_serials, self._Client), |
| 534 |
871,872c879,880 |
| 535 |
< def _decref(token, authkey, state, tls, idset, _Client): |
| 536 |
< idset.discard(token.id) |
| 537 |
--- |
| 538 |
> def _decref(token, serial, authkey, state, tls, idset, _Client): |
| 539 |
> idset.discard(serial) |
| 540 |
1169a1178 |
| 541 |
> collections.abc.MutableSequence.register(BaseListProxy) |
| 542 |
1171c1180 |
| 543 |
< _BaseDictProxy = MakeProxyType('DictProxy', ( |
| 544 |
--- |
| 545 |
> _BaseDictProxy = MakeProxyType('_BaseDictProxy', ( |
| 546 |
1186a1196,1197 |
| 547 |
> collections.abc.MutableMapping.register(_BaseDictProxy) |
| 548 |
> |
| 549 |
diff Python-3.14.0a1/Lib/multiprocessing/synchronize.py Python-3.14.0a2/Lib/multiprocessing/synchronize.py |
| 550 |
24,26c24 |
| 551 |
< # Try to import the mp.synchronize module cleanly, if it fails |
| 552 |
< # raise ImportError for platforms lacking a working sem_open implementation. |
| 553 |
< # See issue 3770 |
| 554 |
--- |
| 555 |
> # TODO: Do any platforms still lack a functioning sem_open? |
| 556 |
29c27 |
| 557 |
< except (ImportError): |
| 558 |
--- |
| 559 |
> except ImportError: |
| 560 |
31,33c29 |
| 561 |
< " implementation, therefore, the required" + |
| 562 |
< " synchronization primitives needed will not" + |
| 563 |
< " function, see issue 3770.") |
| 564 |
--- |
| 565 |
> " implementation. https://github.com/python/cpython/issues/48020.") |
| 566 |
39c35,38 |
| 567 |
< RECURSIVE_MUTEX, SEMAPHORE = list(range(2)) |
| 568 |
--- |
| 569 |
> # These match the enum in Modules/_multiprocessing/semaphore.c |
| 570 |
> RECURSIVE_MUTEX = 0 |
| 571 |
> SEMAPHORE = 1 |
| 572 |
> |
| 573 |
177c176 |
| 574 |
< elif self._semlock._get_value() == 1: |
| 575 |
--- |
| 576 |
> elif not self._semlock._is_zero(): |
| 577 |
203c202 |
| 578 |
< elif self._semlock._get_value() == 1: |
| 579 |
--- |
| 580 |
> elif not self._semlock._is_zero(): |
| 581 |
diff Python-3.14.0a1/Lib/multiprocessing/util.py Python-3.14.0a2/Lib/multiprocessing/util.py |
| 582 |
441d440 |
| 583 |
< import subprocess |
| 584 |
diff Python-3.14.0a1/Lib/test/_test_multiprocessing.py Python-3.14.0a2/Lib/test/_test_multiprocessing.py |
| 585 |
14a15 |
| 586 |
> import importlib |
| 587 |
18a20 |
| 588 |
> import collections.abc |
| 589 |
21a24 |
| 590 |
> import shutil |
| 591 |
23a27 |
| 592 |
> import tempfile |
| 593 |
256a261,263 |
| 594 |
> # If not empty, limit which start method suites run this class. |
| 595 |
> START_METHODS: set[str] = set() |
| 596 |
> start_method = None # set by install_tests_in_module_dict() |
| 597 |
1364a1372,1431 |
| 598 |
> @staticmethod |
| 599 |
> def _acquire(lock, l=None): |
| 600 |
> lock.acquire() |
| 601 |
> if l is not None: |
| 602 |
> l.append(repr(lock)) |
| 603 |
> |
| 604 |
> @staticmethod |
| 605 |
> def _acquire_event(lock, event): |
| 606 |
> lock.acquire() |
| 607 |
> event.set() |
| 608 |
> time.sleep(1.0) |
| 609 |
> |
| 610 |
> def test_repr_lock(self): |
| 611 |
> if self.TYPE != 'processes': |
| 612 |
> self.skipTest('test not appropriate for {}'.format(self.TYPE)) |
| 613 |
> |
| 614 |
> lock = self.Lock() |
| 615 |
> self.assertEqual(f'<Lock(owner=None)>', repr(lock)) |
| 616 |
> |
| 617 |
> lock.acquire() |
| 618 |
> self.assertEqual(f'<Lock(owner=MainProcess)>', repr(lock)) |
| 619 |
> lock.release() |
| 620 |
> |
| 621 |
> tname = 'T1' |
| 622 |
> l = [] |
| 623 |
> t = threading.Thread(target=self._acquire, |
| 624 |
> args=(lock, l), |
| 625 |
> name=tname) |
| 626 |
> t.start() |
| 627 |
> time.sleep(0.1) |
| 628 |
> self.assertEqual(f'<Lock(owner=MainProcess|{tname})>', l[0]) |
| 629 |
> lock.release() |
| 630 |
> |
| 631 |
> t = threading.Thread(target=self._acquire, |
| 632 |
> args=(lock,), |
| 633 |
> name=tname) |
| 634 |
> t.start() |
| 635 |
> time.sleep(0.1) |
| 636 |
> self.assertEqual('<Lock(owner=SomeOtherThread)>', repr(lock)) |
| 637 |
> lock.release() |
| 638 |
> |
| 639 |
> pname = 'P1' |
| 640 |
> l = multiprocessing.Manager().list() |
| 641 |
> p = self.Process(target=self._acquire, |
| 642 |
> args=(lock, l), |
| 643 |
> name=pname) |
| 644 |
> p.start() |
| 645 |
> p.join() |
| 646 |
> self.assertEqual(f'<Lock(owner={pname})>', l[0]) |
| 647 |
> |
| 648 |
> lock = self.Lock() |
| 649 |
> event = self.Event() |
| 650 |
> p = self.Process(target=self._acquire_event, |
| 651 |
> args=(lock, event), |
| 652 |
> name='P2') |
| 653 |
> p.start() |
| 654 |
> event.wait() |
| 655 |
> self.assertEqual(f'<Lock(owner=SomeOtherProcess)>', repr(lock)) |
| 656 |
> p.terminate() |
| 657 |
> |
| 658 |
1371a1439,1500 |
| 659 |
> @staticmethod |
| 660 |
> def _acquire_release(lock, timeout, l=None, n=1): |
| 661 |
> for _ in range(n): |
| 662 |
> lock.acquire() |
| 663 |
> if l is not None: |
| 664 |
> l.append(repr(lock)) |
| 665 |
> time.sleep(timeout) |
| 666 |
> for _ in range(n): |
| 667 |
> lock.release() |
| 668 |
> |
| 669 |
> def test_repr_rlock(self): |
| 670 |
> if self.TYPE != 'processes': |
| 671 |
> self.skipTest('test not appropriate for {}'.format(self.TYPE)) |
| 672 |
> |
| 673 |
> lock = self.RLock() |
| 674 |
> self.assertEqual('<RLock(None, 0)>', repr(lock)) |
| 675 |
> |
| 676 |
> n = 3 |
| 677 |
> for _ in range(n): |
| 678 |
> lock.acquire() |
| 679 |
> self.assertEqual(f'<RLock(MainProcess, {n})>', repr(lock)) |
| 680 |
> for _ in range(n): |
| 681 |
> lock.release() |
| 682 |
> |
| 683 |
> t, l = [], [] |
| 684 |
> for i in range(n): |
| 685 |
> t.append(threading.Thread(target=self._acquire_release, |
| 686 |
> args=(lock, 0.1, l, i+1), |
| 687 |
> name=f'T{i+1}')) |
| 688 |
> t[-1].start() |
| 689 |
> for t_ in t: |
| 690 |
> t_.join() |
| 691 |
> for i in range(n): |
| 692 |
> self.assertIn(f'<RLock(MainProcess|T{i+1}, {i+1})>', l) |
| 693 |
> |
| 694 |
> |
| 695 |
> t = threading.Thread(target=self._acquire_release, |
| 696 |
> args=(lock, 0.2), |
| 697 |
> name=f'T1') |
| 698 |
> t.start() |
| 699 |
> time.sleep(0.1) |
| 700 |
> self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(lock)) |
| 701 |
> time.sleep(0.2) |
| 702 |
> |
| 703 |
> pname = 'P1' |
| 704 |
> l = multiprocessing.Manager().list() |
| 705 |
> p = self.Process(target=self._acquire_release, |
| 706 |
> args=(lock, 0.1, l), |
| 707 |
> name=pname) |
| 708 |
> p.start() |
| 709 |
> p.join() |
| 710 |
> self.assertEqual(f'<RLock({pname}, 1)>', l[0]) |
| 711 |
> |
| 712 |
> event = self.Event() |
| 713 |
> lock = self.RLock() |
| 714 |
> p = self.Process(target=self._acquire_event, |
| 715 |
> args=(lock, event)) |
| 716 |
> p.start() |
| 717 |
> event.wait() |
| 718 |
> self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', repr(lock)) |
| 719 |
> p.join() |
| 720 |
> |
| 721 |
2333a2463,2479 |
| 722 |
> def test_list_isinstance(self): |
| 723 |
> a = self.list() |
| 724 |
> self.assertIsInstance(a, collections.abc.MutableSequence) |
| 725 |
> |
| 726 |
> # MutableSequence also has __iter__, but we can iterate over |
| 727 |
> # ListProxy using __getitem__ instead. Adding __iter__ to ListProxy |
| 728 |
> # would change the behavior of a list modified during iteration. |
| 729 |
> mutable_sequence_methods = ( |
| 730 |
> '__contains__', '__delitem__', '__getitem__', '__iadd__', |
| 731 |
> '__len__', '__reversed__', '__setitem__', 'append', |
| 732 |
> 'clear', 'count', 'extend', 'index', 'insert', 'pop', 'remove', |
| 733 |
> 'reverse', |
| 734 |
> ) |
| 735 |
> for name in mutable_sequence_methods: |
| 736 |
> with self.subTest(name=name): |
| 737 |
> self.assertTrue(callable(getattr(a, name))) |
| 738 |
> |
| 739 |
2373a2520,2532 |
| 740 |
> def test_dict_isinstance(self): |
| 741 |
> a = self.dict() |
| 742 |
> self.assertIsInstance(a, collections.abc.MutableMapping) |
| 743 |
> |
| 744 |
> mutable_mapping_methods = ( |
| 745 |
> '__contains__', '__delitem__', '__eq__', '__getitem__', '__iter__', |
| 746 |
> '__len__', '__ne__', '__setitem__', 'clear', 'get', 'items', |
| 747 |
> 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', |
| 748 |
> ) |
| 749 |
> for name in mutable_mapping_methods: |
| 750 |
> with self.subTest(name=name): |
| 751 |
> self.assertTrue(callable(getattr(a, name))) |
| 752 |
> |
| 753 |
5763a5923,5924 |
| 754 |
> @unittest.skipIf(sys.platform.startswith("netbsd"), |
| 755 |
> "gh-125620: Skip on NetBSD due to long wait for SIGKILL process termination.") |
| 756 |
6266a6428,6497 |
| 757 |
> class _TestSpawnedSysPath(BaseTestCase): |
| 758 |
> """Test that sys.path is setup in forkserver and spawn processes.""" |
| 759 |
> |
| 760 |
> ALLOWED_TYPES = {'processes'} |
| 761 |
> # Not applicable to fork which inherits everything from the process as is. |
| 762 |
> START_METHODS = {"forkserver", "spawn"} |
| 763 |
> |
| 764 |
> def setUp(self): |
| 765 |
> self._orig_sys_path = list(sys.path) |
| 766 |
> self._temp_dir = tempfile.mkdtemp(prefix="test_sys_path-") |
| 767 |
> self._mod_name = "unique_test_mod" |
| 768 |
> module_path = os.path.join(self._temp_dir, f"{self._mod_name}.py") |
| 769 |
> with open(module_path, "w", encoding="utf-8") as mod: |
| 770 |
> mod.write("# A simple test module\n") |
| 771 |
> sys.path[:] = [p for p in sys.path if p] # remove any existing ""s |
| 772 |
> sys.path.insert(0, self._temp_dir) |
| 773 |
> sys.path.insert(0, "") # Replaced with an abspath in child. |
| 774 |
> self.assertIn(self.start_method, self.START_METHODS) |
| 775 |
> self._ctx = multiprocessing.get_context(self.start_method) |
| 776 |
> |
| 777 |
> def tearDown(self): |
| 778 |
> sys.path[:] = self._orig_sys_path |
| 779 |
> shutil.rmtree(self._temp_dir, ignore_errors=True) |
| 780 |
> |
| 781 |
> @staticmethod |
| 782 |
> def enq_imported_module_names(queue): |
| 783 |
> queue.put(tuple(sys.modules)) |
| 784 |
> |
| 785 |
> def test_forkserver_preload_imports_sys_path(self): |
| 786 |
> if self._ctx.get_start_method() != "forkserver": |
| 787 |
> self.skipTest("forkserver specific test.") |
| 788 |
> self.assertNotIn(self._mod_name, sys.modules) |
| 789 |
> multiprocessing.forkserver._forkserver._stop() # Must be fresh. |
| 790 |
> self._ctx.set_forkserver_preload( |
| 791 |
> ["test.test_multiprocessing_forkserver", self._mod_name]) |
| 792 |
> q = self._ctx.Queue() |
| 793 |
> proc = self._ctx.Process( |
| 794 |
> target=self.enq_imported_module_names, args=(q,)) |
| 795 |
> proc.start() |
| 796 |
> proc.join() |
| 797 |
> child_imported_modules = q.get() |
| 798 |
> q.close() |
| 799 |
> self.assertIn(self._mod_name, child_imported_modules) |
| 800 |
> |
| 801 |
> @staticmethod |
| 802 |
> def enq_sys_path_and_import(queue, mod_name): |
| 803 |
> queue.put(sys.path) |
| 804 |
> try: |
| 805 |
> importlib.import_module(mod_name) |
| 806 |
> except ImportError as exc: |
| 807 |
> queue.put(exc) |
| 808 |
> else: |
| 809 |
> queue.put(None) |
| 810 |
> |
| 811 |
> def test_child_sys_path(self): |
| 812 |
> q = self._ctx.Queue() |
| 813 |
> proc = self._ctx.Process( |
| 814 |
> target=self.enq_sys_path_and_import, args=(q, self._mod_name)) |
| 815 |
> proc.start() |
| 816 |
> proc.join() |
| 817 |
> child_sys_path = q.get() |
| 818 |
> import_error = q.get() |
| 819 |
> q.close() |
| 820 |
> self.assertNotIn("", child_sys_path) # replaced by an abspath |
| 821 |
> self.assertIn(self._temp_dir, child_sys_path) # our addition |
| 822 |
> # ignore the first element, it is the absolute "" replacement |
| 823 |
> self.assertEqual(child_sys_path[1:], sys.path[1:]) |
| 824 |
> self.assertIsNone(import_error, msg=f"child could not import {self._mod_name}") |
| 825 |
> |
| 826 |
> |
| 827 |
6460a6692,6693 |
| 828 |
> if base.START_METHODS and start_method not in base.START_METHODS: |
| 829 |
> continue # class not intended for this start method. |
| 830 |
6473a6707 |
| 831 |
> Temp.start_method = start_method |
| 832 |
# ---------------------------------------------------------------------- |
| 833 |
diff Python-3.14.0a2/Lib/multiprocessing/connection.py Python-3.14.0a3/Lib/multiprocessing/connection.py |
| 834 |
183a184,187 |
| 835 |
> def _detach(self): |
| 836 |
> """Stop managing the underlying file descriptor or handle.""" |
| 837 |
> self._handle = None |
| 838 |
> |
| 839 |
962c966 |
| 840 |
< raise AuthenticationError('challenge too short: {len(message)} bytes') |
| 841 |
--- |
| 842 |
> raise AuthenticationError(f'challenge too short: {len(message)} bytes') |
| 843 |
diff Python-3.14.0a2/Lib/multiprocessing/forkserver.py Python-3.14.0a3/Lib/multiprocessing/forkserver.py |
| 844 |
11a12 |
| 845 |
> from . import AuthenticationError |
| 846 |
27a29 |
| 847 |
> _AUTHKEY_LEN = 32 # <= PIPEBUF so it fits a single write to an empty pipe. |
| 848 |
35a38 |
| 849 |
> self._forkserver_authkey = None |
| 850 |
61a65 |
| 851 |
> self._forkserver_authkey = None |
| 852 |
85a90 |
| 853 |
> assert self._forkserver_authkey |
| 854 |
95a101,112 |
| 855 |
> client.setblocking(True) |
| 856 |
> wrapped_client = connection.Connection(client.fileno()) |
| 857 |
> # The other side of this exchange happens in the child as |
| 858 |
> # implemented in main(). |
| 859 |
> try: |
| 860 |
> connection.answer_challenge( |
| 861 |
> wrapped_client, self._forkserver_authkey) |
| 862 |
> connection.deliver_challenge( |
| 863 |
> wrapped_client, self._forkserver_authkey) |
| 864 |
> finally: |
| 865 |
> wrapped_client._detach() |
| 866 |
> del wrapped_client |
| 867 |
122a140 |
| 868 |
> self._forkserver_authkey = None |
| 869 |
133c151 |
| 870 |
< data = {x: y for x, y in data.items() if x in desired_keys} |
| 871 |
--- |
| 872 |
> main_kws = {x: y for x, y in data.items() if x in desired_keys} |
| 873 |
135c153 |
| 874 |
< data = {} |
| 875 |
--- |
| 876 |
> main_kws = {} |
| 877 |
146a165,166 |
| 878 |
> # A short lived pipe to initialize the forkserver authkey. |
| 879 |
> authkey_r, authkey_w = os.pipe() |
| 880 |
148c168,169 |
| 881 |
< fds_to_pass = [listener.fileno(), alive_r] |
| 882 |
--- |
| 883 |
> fds_to_pass = [listener.fileno(), alive_r, authkey_r] |
| 884 |
> main_kws['authkey_r'] = authkey_r |
| 885 |
150c171 |
| 886 |
< data) |
| 887 |
--- |
| 888 |
> main_kws) |
| 889 |
156a178 |
| 890 |
> os.close(authkey_w) |
| 891 |
159a182,189 |
| 892 |
> os.close(authkey_r) |
| 893 |
> # Authenticate our control socket to prevent access from |
| 894 |
> # processes we have not shared this key with. |
| 895 |
> try: |
| 896 |
> self._forkserver_authkey = os.urandom(_AUTHKEY_LEN) |
| 897 |
> os.write(authkey_w, self._forkserver_authkey) |
| 898 |
> finally: |
| 899 |
> os.close(authkey_w) |
| 900 |
168,169c198,209 |
| 901 |
< def main(listener_fd, alive_r, preload, main_path=None, sys_path=None): |
| 902 |
< '''Run forkserver.''' |
| 903 |
--- |
| 904 |
> def main(listener_fd, alive_r, preload, main_path=None, sys_path=None, |
| 905 |
> *, authkey_r=None): |
| 906 |
> """Run forkserver.""" |
| 907 |
> if authkey_r is not None: |
| 908 |
> try: |
| 909 |
> authkey = os.read(authkey_r, _AUTHKEY_LEN) |
| 910 |
> assert len(authkey) == _AUTHKEY_LEN, f'{len(authkey)} < {_AUTHKEY_LEN}' |
| 911 |
> finally: |
| 912 |
> os.close(authkey_r) |
| 913 |
> else: |
| 914 |
> authkey = b'' |
| 915 |
> |
| 916 |
260,261c300,317 |
| 917 |
< # Receive fds from client |
| 918 |
< fds = reduction.recvfds(s, MAXFDS_TO_SEND + 1) |
| 919 |
--- |
| 920 |
> try: |
| 921 |
> if authkey: |
| 922 |
> wrapped_s = connection.Connection(s.fileno()) |
| 923 |
> # The other side of this exchange happens in |
| 924 |
> # in connect_to_new_process(). |
| 925 |
> try: |
| 926 |
> connection.deliver_challenge( |
| 927 |
> wrapped_s, authkey) |
| 928 |
> connection.answer_challenge( |
| 929 |
> wrapped_s, authkey) |
| 930 |
> finally: |
| 931 |
> wrapped_s._detach() |
| 932 |
> del wrapped_s |
| 933 |
> # Receive fds from client |
| 934 |
> fds = reduction.recvfds(s, MAXFDS_TO_SEND + 1) |
| 935 |
> except (EOFError, BrokenPipeError, AuthenticationError): |
| 936 |
> s.close() |
| 937 |
> continue |
| 938 |
diff Python-3.14.0a2/Lib/multiprocessing/reduction.py Python-3.14.0a3/Lib/multiprocessing/reduction.py |
| 939 |
142,144d141 |
| 940 |
< # On MacOSX we should acknowledge receipt of fds -- see Issue14669 |
| 941 |
< ACKNOWLEDGE = sys.platform == 'darwin' |
| 942 |
< |
| 943 |
150c147 |
| 944 |
< if ACKNOWLEDGE and sock.recv(1) != b'A': |
| 945 |
--- |
| 946 |
> if sock.recv(1) != b'A': |
| 947 |
161,162c158,162 |
| 948 |
< if ACKNOWLEDGE: |
| 949 |
< sock.send(b'A') |
| 950 |
--- |
| 951 |
> # We send/recv an Ack byte after the fds to work around an old |
| 952 |
> # macOS bug; it isn't clear if this is still required but it |
| 953 |
> # makes unit testing fd sending easier. |
| 954 |
> # See: https://github.com/python/cpython/issues/58874 |
| 955 |
> sock.send(b'A') # Acknowledge |
| 956 |
diff Python-3.14.0a2/Lib/test/_test_multiprocessing.py Python-3.14.0a3/Lib/test/_test_multiprocessing.py |
| 957 |
849,850c849,850 |
| 958 |
< @classmethod |
| 959 |
< def _sleep_and_set_event(self, evt, delay=0.0): |
| 960 |
--- |
| 961 |
> @staticmethod |
| 962 |
> def _sleep_and_set_event(evt, delay=0.0): |
| 963 |
900a901,950 |
| 964 |
> def test_forkserver_auth_is_enabled(self): |
| 965 |
> if self.TYPE == "threads": |
| 966 |
> self.skipTest(f"test not appropriate for {self.TYPE}") |
| 967 |
> if multiprocessing.get_start_method() != "forkserver": |
| 968 |
> self.skipTest("forkserver start method specific") |
| 969 |
> |
| 970 |
> forkserver = multiprocessing.forkserver._forkserver |
| 971 |
> forkserver.ensure_running() |
| 972 |
> self.assertTrue(forkserver._forkserver_pid) |
| 973 |
> authkey = forkserver._forkserver_authkey |
| 974 |
> self.assertTrue(authkey) |
| 975 |
> self.assertGreater(len(authkey), 15) |
| 976 |
> addr = forkserver._forkserver_address |
| 977 |
> self.assertTrue(addr) |
| 978 |
> |
| 979 |
> # Demonstrate that a raw auth handshake, as Client performs, does not |
| 980 |
> # raise an error. |
| 981 |
> client = multiprocessing.connection.Client(addr, authkey=authkey) |
| 982 |
> client.close() |
| 983 |
> |
| 984 |
> # That worked, now launch a quick process. |
| 985 |
> proc = self.Process(target=sys.exit) |
| 986 |
> proc.start() |
| 987 |
> proc.join() |
| 988 |
> self.assertEqual(proc.exitcode, 0) |
| 989 |
> |
| 990 |
> def test_forkserver_without_auth_fails(self): |
| 991 |
> if self.TYPE == "threads": |
| 992 |
> self.skipTest(f"test not appropriate for {self.TYPE}") |
| 993 |
> if multiprocessing.get_start_method() != "forkserver": |
| 994 |
> self.skipTest("forkserver start method specific") |
| 995 |
> |
| 996 |
> forkserver = multiprocessing.forkserver._forkserver |
| 997 |
> forkserver.ensure_running() |
| 998 |
> self.assertTrue(forkserver._forkserver_pid) |
| 999 |
> authkey_len = len(forkserver._forkserver_authkey) |
| 1000 |
> with unittest.mock.patch.object( |
| 1001 |
> forkserver, '_forkserver_authkey', None): |
| 1002 |
> # With an incorrect authkey we should get an auth rejection |
| 1003 |
> # rather than the above protocol error. |
| 1004 |
> forkserver._forkserver_authkey = b'T' * authkey_len |
| 1005 |
> proc = self.Process(target=sys.exit) |
| 1006 |
> with self.assertRaises(multiprocessing.AuthenticationError): |
| 1007 |
> proc.start() |
| 1008 |
> del proc |
| 1009 |
> |
| 1010 |
> # authkey restored, launching processes should work again. |
| 1011 |
> proc = self.Process(target=sys.exit) |
| 1012 |
> proc.start() |
| 1013 |
> proc.join() |
| 1014 |
# ---------------------------------------------------------------------- |
| 1015 |
diff Python-3.14.0a3/Lib/multiprocessing/resource_tracker.py Python-3.14.0a4/Lib/multiprocessing/resource_tracker.py |
| 1016 |
157a158 |
| 1017 |
> prev_sigmask = None |
| 1018 |
160c161 |
| 1019 |
< signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) |
| 1020 |
--- |
| 1021 |
> prev_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) |
| 1022 |
163,164c164,165 |
| 1023 |
< if _HAVE_SIGMASK: |
| 1024 |
< signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS) |
| 1025 |
--- |
| 1026 |
> if prev_sigmask is not None: |
| 1027 |
> signal.pthread_sigmask(signal.SIG_SETMASK, prev_sigmask) |
| 1028 |
diff Python-3.14.0a3/Lib/test/_test_multiprocessing.py Python-3.14.0a4/Lib/test/_test_multiprocessing.py |
| 1029 |
6047a6048,6068 |
| 1030 |
> @unittest.skipUnless(hasattr(signal, "pthread_sigmask"), "pthread_sigmask is not available") |
| 1031 |
> def test_resource_tracker_blocked_signals(self): |
| 1032 |
> # |
| 1033 |
> # gh-127586: Check that resource_tracker does not override blocked signals of caller. |
| 1034 |
> # |
| 1035 |
> from multiprocessing.resource_tracker import ResourceTracker |
| 1036 |
> orig_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, set()) |
| 1037 |
> signals = {signal.SIGTERM, signal.SIGINT, signal.SIGUSR1} |
| 1038 |
> |
| 1039 |
> try: |
| 1040 |
> for sig in signals: |
| 1041 |
> signal.pthread_sigmask(signal.SIG_SETMASK, {sig}) |
| 1042 |
> self.assertEqual(signal.pthread_sigmask(signal.SIG_BLOCK, set()), {sig}) |
| 1043 |
> tracker = ResourceTracker() |
| 1044 |
> tracker.ensure_running() |
| 1045 |
> self.assertEqual(signal.pthread_sigmask(signal.SIG_BLOCK, set()), {sig}) |
| 1046 |
> tracker._stop() |
| 1047 |
> finally: |
| 1048 |
> # restore sigmask to what it was before executing test |
| 1049 |
> signal.pthread_sigmask(signal.SIG_SETMASK, orig_sigmask) |
| 1050 |
> |
| 1051 |
# ---------------------------------------------------------------------- |
| 1052 |
diff Python-3.14.0a4/Modules/_multiprocessing/semaphore.c Python-3.14.0a5/Modules/_multiprocessing/semaphore.c |
| 1053 |
30a31,32 |
| 1054 |
> #define _SemLockObject_CAST(op) ((SemLockObject *)(op)) |
| 1055 |
> |
| 1056 |
579c581 |
| 1057 |
< semlock_dealloc(SemLockObject* self) |
| 1058 |
--- |
| 1059 |
> semlock_dealloc(PyObject *op) |
| 1060 |
580a583 |
| 1061 |
> SemLockObject *self = _SemLockObject_CAST(op); |
| 1062 |
721c724 |
| 1063 |
< semlock_traverse(SemLockObject *s, visitproc visit, void *arg) |
| 1064 |
--- |
| 1065 |
> semlock_traverse(PyObject *s, visitproc visit, void *arg) |
| 1066 |
diff Python-3.14.0a4/Modules/_multiprocessing/clinic/semaphore.c.h Python-3.14.0a5/Modules/_multiprocessing/clinic/semaphore.c.h |
| 1067 |
28c28 |
| 1068 |
< _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1069 |
--- |
| 1070 |
> _multiprocessing_SemLock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1071 |
81c81 |
| 1072 |
< return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj); |
| 1073 |
--- |
| 1074 |
> return_value = _multiprocessing_SemLock_acquire_impl((SemLockObject *)self, blocking, timeout_obj); |
| 1075 |
105c105 |
| 1076 |
< _multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1077 |
--- |
| 1078 |
> _multiprocessing_SemLock_release(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1079 |
110c110 |
| 1080 |
< return_value = _multiprocessing_SemLock_release_impl(self); |
| 1081 |
--- |
| 1082 |
> return_value = _multiprocessing_SemLock_release_impl((SemLockObject *)self); |
| 1083 |
134c134 |
| 1084 |
< _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1085 |
--- |
| 1086 |
> _multiprocessing_SemLock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1087 |
187c187 |
| 1088 |
< return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj); |
| 1089 |
--- |
| 1090 |
> return_value = _multiprocessing_SemLock_acquire_impl((SemLockObject *)self, blocking, timeout_obj); |
| 1091 |
211c211 |
| 1092 |
< _multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1093 |
--- |
| 1094 |
> _multiprocessing_SemLock_release(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1095 |
216c216 |
| 1096 |
< return_value = _multiprocessing_SemLock_release_impl(self); |
| 1097 |
--- |
| 1098 |
> return_value = _multiprocessing_SemLock_release_impl((SemLockObject *)self); |
| 1099 |
361c361 |
| 1100 |
< _multiprocessing_SemLock__count(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1101 |
--- |
| 1102 |
> _multiprocessing_SemLock__count(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1103 |
366c366 |
| 1104 |
< return_value = _multiprocessing_SemLock__count_impl(self); |
| 1105 |
--- |
| 1106 |
> return_value = _multiprocessing_SemLock__count_impl((SemLockObject *)self); |
| 1107 |
389c389 |
| 1108 |
< _multiprocessing_SemLock__is_mine(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1109 |
--- |
| 1110 |
> _multiprocessing_SemLock__is_mine(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1111 |
391c391 |
| 1112 |
< return _multiprocessing_SemLock__is_mine_impl(self); |
| 1113 |
--- |
| 1114 |
> return _multiprocessing_SemLock__is_mine_impl((SemLockObject *)self); |
| 1115 |
411c411 |
| 1116 |
< _multiprocessing_SemLock__get_value(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1117 |
--- |
| 1118 |
> _multiprocessing_SemLock__get_value(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1119 |
413c413 |
| 1120 |
< return _multiprocessing_SemLock__get_value_impl(self); |
| 1121 |
--- |
| 1122 |
> return _multiprocessing_SemLock__get_value_impl((SemLockObject *)self); |
| 1123 |
433c433 |
| 1124 |
< _multiprocessing_SemLock__is_zero(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1125 |
--- |
| 1126 |
> _multiprocessing_SemLock__is_zero(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1127 |
435c435 |
| 1128 |
< return _multiprocessing_SemLock__is_zero_impl(self); |
| 1129 |
--- |
| 1130 |
> return _multiprocessing_SemLock__is_zero_impl((SemLockObject *)self); |
| 1131 |
455c455 |
| 1132 |
< _multiprocessing_SemLock__after_fork(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1133 |
--- |
| 1134 |
> _multiprocessing_SemLock__after_fork(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1135 |
457c457 |
| 1136 |
< return _multiprocessing_SemLock__after_fork_impl(self); |
| 1137 |
--- |
| 1138 |
> return _multiprocessing_SemLock__after_fork_impl((SemLockObject *)self); |
| 1139 |
477c477 |
| 1140 |
< _multiprocessing_SemLock___enter__(SemLockObject *self, PyObject *Py_UNUSED(ignored)) |
| 1141 |
--- |
| 1142 |
> _multiprocessing_SemLock___enter__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1143 |
482c482 |
| 1144 |
< return_value = _multiprocessing_SemLock___enter___impl(self); |
| 1145 |
--- |
| 1146 |
> return_value = _multiprocessing_SemLock___enter___impl((SemLockObject *)self); |
| 1147 |
507c507 |
| 1148 |
< _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 1149 |
--- |
| 1150 |
> _multiprocessing_SemLock___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 1151 |
531c531 |
| 1152 |
< return_value = _multiprocessing_SemLock___exit___impl(self, exc_type, exc_value, exc_tb); |
| 1153 |
--- |
| 1154 |
> return_value = _multiprocessing_SemLock___exit___impl((SemLockObject *)self, exc_type, exc_value, exc_tb); |
| 1155 |
579c579 |
| 1156 |
< /*[clinic end generated code: output=9023d3e48a24afd2 input=a9049054013a1b77]*/ |
| 1157 |
--- |
| 1158 |
> /*[clinic end generated code: output=e28d0fdbfefd1235 input=a9049054013a1b77]*/ |
| 1159 |
diff Python-3.14.0a4/Lib/multiprocessing/connection.py Python-3.14.0a5/Lib/multiprocessing/connection.py |
| 1160 |
856c856 |
| 1161 |
< def _get_digest_name_and_payload(message: bytes) -> (str, bytes): |
| 1162 |
--- |
| 1163 |
> def _get_digest_name_and_payload(message): # type: (bytes) -> tuple[str, bytes] |
| 1164 |
diff Python-3.14.0a4/Lib/multiprocessing/forkserver.py Python-3.14.0a5/Lib/multiprocessing/forkserver.py |
| 1165 |
385,389c385,389 |
| 1166 |
< data = b'' |
| 1167 |
< length = SIGNED_STRUCT.size |
| 1168 |
< while len(data) < length: |
| 1169 |
< s = os.read(fd, length - len(data)) |
| 1170 |
< if not s: |
| 1171 |
--- |
| 1172 |
> data = bytearray(SIGNED_STRUCT.size) |
| 1173 |
> unread = memoryview(data) |
| 1174 |
> while unread: |
| 1175 |
> count = os.readinto(fd, unread) |
| 1176 |
> if count == 0: |
| 1177 |
391c391,392 |
| 1178 |
< data += s |
| 1179 |
--- |
| 1180 |
> unread = unread[count:] |
| 1181 |
> |
| 1182 |
diff Python-3.14.0a4/Lib/multiprocessing/synchronize.py Python-3.14.0a5/Lib/multiprocessing/synchronize.py |
| 1183 |
362c362 |
| 1184 |
< def __repr__(self) -> str: |
| 1185 |
--- |
| 1186 |
> def __repr__(self): |
| 1187 |
diff Python-3.14.0a4/Lib/test/_test_multiprocessing.py Python-3.14.0a5/Lib/test/_test_multiprocessing.py |
| 1188 |
322c322 |
| 1189 |
< self.assertTrue(not current.daemon) |
| 1190 |
--- |
| 1191 |
> self.assertFalse(current.daemon) |
| 1192 |
466c466 |
| 1193 |
< self.assertTrue(type(self.active_children()) is list) |
| 1194 |
--- |
| 1195 |
> self.assertIs(type(self.active_children()), list) |
| 1196 |
586,587c586,587 |
| 1197 |
< self.assertTrue(type(cpus) is int) |
| 1198 |
< self.assertTrue(cpus >= 1) |
| 1199 |
--- |
| 1200 |
> self.assertIsInstance(cpus, int) |
| 1201 |
> self.assertGreaterEqual(cpus, 1) |
| 1202 |
2385,2386c2385,2386 |
| 1203 |
< self.assertFalse(hasattr(arr4, 'get_lock')) |
| 1204 |
< self.assertFalse(hasattr(arr4, 'get_obj')) |
| 1205 |
--- |
| 1206 |
> self.assertNotHasAttr(arr4, 'get_lock') |
| 1207 |
> self.assertNotHasAttr(arr4, 'get_obj') |
| 1208 |
2391,2392c2391,2392 |
| 1209 |
< self.assertFalse(hasattr(arr5, 'get_lock')) |
| 1210 |
< self.assertFalse(hasattr(arr5, 'get_obj')) |
| 1211 |
--- |
| 1212 |
> self.assertNotHasAttr(arr5, 'get_lock') |
| 1213 |
> self.assertNotHasAttr(arr5, 'get_obj') |
| 1214 |
2465,2466c2465,2466 |
| 1215 |
< self.assertFalse(hasattr(arr4, 'get_lock')) |
| 1216 |
< self.assertFalse(hasattr(arr4, 'get_obj')) |
| 1217 |
--- |
| 1218 |
> self.assertNotHasAttr(arr4, 'get_lock') |
| 1219 |
> self.assertNotHasAttr(arr4, 'get_obj') |
| 1220 |
2471,2472c2471,2472 |
| 1221 |
< self.assertFalse(hasattr(arr5, 'get_lock')) |
| 1222 |
< self.assertFalse(hasattr(arr5, 'get_obj')) |
| 1223 |
--- |
| 1224 |
> self.assertNotHasAttr(arr5, 'get_lock') |
| 1225 |
> self.assertNotHasAttr(arr5, 'get_obj') |
| 1226 |
2660,2661c2660,2661 |
| 1227 |
< self.assertTrue(hasattr(n, 'name')) |
| 1228 |
< self.assertTrue(not hasattr(n, 'job')) |
| 1229 |
--- |
| 1230 |
> self.assertHasAttr(n, 'name') |
| 1231 |
> self.assertNotHasAttr(n, 'job') |
| 1232 |
4941,4942c4941 |
| 1233 |
< self.assertTrue(hasattr(mod, '__all__'), name) |
| 1234 |
< |
| 1235 |
--- |
| 1236 |
> self.assertHasAttr(mod, '__all__', name) |
| 1237 |
4944,4947c4943 |
| 1238 |
< self.assertTrue( |
| 1239 |
< hasattr(mod, attr), |
| 1240 |
< '%r does not have attribute %r' % (mod, attr) |
| 1241 |
< ) |
| 1242 |
--- |
| 1243 |
> self.assertHasAttr(mod, attr) |
| 1244 |
4960c4956 |
| 1245 |
< self.assertTrue(logger is not None) |
| 1246 |
--- |
| 1247 |
> self.assertIsNotNone(logger) |
| 1248 |
5756,5758c5752,5753 |
| 1249 |
< self.assertTrue(type(ctx).__name__.lower().startswith(method)) |
| 1250 |
< self.assertTrue( |
| 1251 |
< ctx.Process.__name__.lower().startswith(method)) |
| 1252 |
--- |
| 1253 |
> self.assertStartsWith(type(ctx).__name__.lower(), method) |
| 1254 |
> self.assertStartsWith(ctx.Process.__name__.lower(), method) |
| 1255 |
5959,5961c5954,5956 |
| 1256 |
< self.assertTrue(issubclass(the_warn.category, UserWarning)) |
| 1257 |
< self.assertTrue("resource_tracker: process died" |
| 1258 |
< in str(the_warn.message)) |
| 1259 |
--- |
| 1260 |
> self.assertIsSubclass(the_warn.category, UserWarning) |
| 1261 |
> self.assertIn("resource_tracker: process died", |
| 1262 |
> str(the_warn.message)) |
| 1263 |
6166,6167c6161,6162 |
| 1264 |
< self.assertFalse( |
| 1265 |
< any(process.is_alive() for process in forked_processes)) |
| 1266 |
--- |
| 1267 |
> for process in forked_processes: |
| 1268 |
> self.assertFalse(process.is_alive(), process) |
| 1269 |
# ---------------------------------------------------------------------- |
| 1270 |
diff Python-3.14.0a5/Modules/_multiprocessing/clinic/semaphore.c.h Python-3.14.0a6/Modules/_multiprocessing/clinic/semaphore.c.h |
| 1271 |
326c326 |
| 1272 |
< _multiprocessing_SemLock__rebuild(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs) |
| 1273 |
--- |
| 1274 |
> _multiprocessing_SemLock__rebuild(PyObject *type, PyObject *const *args, Py_ssize_t nargs) |
| 1275 |
338c338 |
| 1276 |
< return_value = _multiprocessing_SemLock__rebuild_impl(type, handle, kind, maxvalue, name); |
| 1277 |
--- |
| 1278 |
> return_value = _multiprocessing_SemLock__rebuild_impl((PyTypeObject *)type, handle, kind, maxvalue, name); |
| 1279 |
579c579 |
| 1280 |
< /*[clinic end generated code: output=e28d0fdbfefd1235 input=a9049054013a1b77]*/ |
| 1281 |
--- |
| 1282 |
> /*[clinic end generated code: output=dddd8e989525f565 input=a9049054013a1b77]*/ |
| 1283 |
diff Python-3.14.0a5/Lib/multiprocessing/managers.py Python-3.14.0a6/Lib/multiprocessing/managers.py |
| 1284 |
1197a1198,1227 |
| 1285 |
> _BaseSetProxy = MakeProxyType("_BaseSetProxy", ( |
| 1286 |
> '__and__', '__class_getitem__', '__contains__', '__iand__', '__ior__', |
| 1287 |
> '__isub__', '__iter__', '__ixor__', '__len__', '__or__', '__rand__', |
| 1288 |
> '__ror__', '__rsub__', '__rxor__', '__sub__', '__xor__', |
| 1289 |
> '__ge__', '__gt__', '__le__', '__lt__', |
| 1290 |
> 'add', 'clear', 'copy', 'difference', 'difference_update', 'discard', |
| 1291 |
> 'intersection', 'intersection_update', 'isdisjoint', 'issubset', |
| 1292 |
> 'issuperset', 'pop', 'remove', 'symmetric_difference', |
| 1293 |
> 'symmetric_difference_update', 'union', 'update', |
| 1294 |
> )) |
| 1295 |
> |
| 1296 |
> class SetProxy(_BaseSetProxy): |
| 1297 |
> def __ior__(self, value): |
| 1298 |
> self._callmethod('__ior__', (value,)) |
| 1299 |
> return self |
| 1300 |
> def __iand__(self, value): |
| 1301 |
> self._callmethod('__iand__', (value,)) |
| 1302 |
> return self |
| 1303 |
> def __ixor__(self, value): |
| 1304 |
> self._callmethod('__ixor__', (value,)) |
| 1305 |
> return self |
| 1306 |
> def __isub__(self, value): |
| 1307 |
> self._callmethod('__isub__', (value,)) |
| 1308 |
> return self |
| 1309 |
> |
| 1310 |
> __class_getitem__ = classmethod(types.GenericAlias) |
| 1311 |
> |
| 1312 |
> collections.abc.MutableMapping.register(_BaseSetProxy) |
| 1313 |
> |
| 1314 |
> |
| 1315 |
1247a1278 |
| 1316 |
> SyncManager.register('set', set, SetProxy) |
| 1317 |
diff Python-3.14.0a5/Lib/test/_test_multiprocessing.py Python-3.14.0a6/Lib/test/_test_multiprocessing.py |
| 1318 |
592c592,593 |
| 1319 |
< p = self.Process(target=time.sleep, args=(DELTA,)) |
| 1320 |
--- |
| 1321 |
> event = self.Event() |
| 1322 |
> p = self.Process(target=event.wait, args=()) |
| 1323 |
595,597c596,601 |
| 1324 |
< p.daemon = True |
| 1325 |
< p.start() |
| 1326 |
< self.assertIn(p, self.active_children()) |
| 1327 |
--- |
| 1328 |
> try: |
| 1329 |
> p.daemon = True |
| 1330 |
> p.start() |
| 1331 |
> self.assertIn(p, self.active_children()) |
| 1332 |
> finally: |
| 1333 |
> event.set() |
| 1334 |
1524,1527c1528,1529 |
| 1335 |
< |
| 1336 |
< t = threading.Thread(target=self._acquire_release, |
| 1337 |
< args=(lock, 0.2), |
| 1338 |
< name=f'T1') |
| 1339 |
--- |
| 1340 |
> rlock = self.RLock() |
| 1341 |
> t = threading.Thread(target=rlock.acquire) |
| 1342 |
1529,1531c1531,1532 |
| 1343 |
< time.sleep(0.1) |
| 1344 |
< self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(lock)) |
| 1345 |
< time.sleep(0.2) |
| 1346 |
--- |
| 1347 |
> t.join() |
| 1348 |
> self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(rlock)) |
| 1349 |
1542,1545c1543,1544 |
| 1350 |
< event = self.Event() |
| 1351 |
< lock = self.RLock() |
| 1352 |
< p = self.Process(target=self._acquire_event, |
| 1353 |
< args=(lock, event)) |
| 1354 |
--- |
| 1355 |
> rlock = self.RLock() |
| 1356 |
> p = self.Process(target=self._acquire, args=(rlock,)) |
| 1357 |
1547,1548d1545 |
| 1358 |
< event.wait() |
| 1359 |
< self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', repr(lock)) |
| 1360 |
1549a1547 |
| 1361 |
> self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', repr(rlock)) |
| 1362 |
1631c1629 |
| 1363 |
< for i in range(10): |
| 1364 |
--- |
| 1365 |
> for _ in support.sleeping_retry(support.SHORT_TIMEOUT): |
| 1366 |
1637,1638c1635 |
| 1367 |
< time.sleep(DELTA) |
| 1368 |
< time.sleep(DELTA) |
| 1369 |
--- |
| 1370 |
> |
| 1371 |
1660d1656 |
| 1372 |
< self.addCleanup(p.join) |
| 1373 |
1662,1665c1658,1660 |
| 1374 |
< p = threading.Thread(target=self.f, args=(cond, sleeping, woken)) |
| 1375 |
< p.daemon = True |
| 1376 |
< p.start() |
| 1377 |
< self.addCleanup(p.join) |
| 1378 |
--- |
| 1379 |
> t = threading.Thread(target=self.f, args=(cond, sleeping, woken)) |
| 1380 |
> t.daemon = True |
| 1381 |
> t.start() |
| 1382 |
1672,1673c1667 |
| 1383 |
< time.sleep(DELTA) |
| 1384 |
< self.assertReturnsIfImplemented(0, get_value, woken) |
| 1385 |
--- |
| 1386 |
> self.assertReachesEventually(lambda: get_value(woken), 0) |
| 1387 |
1681,1682c1675 |
| 1388 |
< time.sleep(DELTA) |
| 1389 |
< self.assertReturnsIfImplemented(1, get_value, woken) |
| 1390 |
--- |
| 1391 |
> self.assertReachesEventually(lambda: get_value(woken), 1) |
| 1392 |
1690,1691c1683 |
| 1393 |
< time.sleep(DELTA) |
| 1394 |
< self.assertReturnsIfImplemented(2, get_value, woken) |
| 1395 |
--- |
| 1396 |
> self.assertReachesEventually(lambda: get_value(woken), 2) |
| 1397 |
1695c1687,1689 |
| 1398 |
< p.join() |
| 1399 |
--- |
| 1400 |
> |
| 1401 |
> threading_helper.join_thread(t) |
| 1402 |
> join_process(p) |
| 1403 |
1702a1697 |
| 1404 |
> workers = [] |
| 1405 |
1708c1703 |
| 1406 |
< self.addCleanup(p.join) |
| 1407 |
--- |
| 1408 |
> workers.append(p) |
| 1409 |
1714c1709 |
| 1410 |
< self.addCleanup(t.join) |
| 1411 |
--- |
| 1412 |
> workers.append(t) |
| 1413 |
1733c1728 |
| 1414 |
< self.addCleanup(p.join) |
| 1415 |
--- |
| 1416 |
> workers.append(p) |
| 1417 |
1738c1733 |
| 1418 |
< self.addCleanup(t.join) |
| 1419 |
--- |
| 1420 |
> workers.append(t) |
| 1421 |
1754c1749,1751 |
| 1422 |
< self.assertReachesEventually(lambda: get_value(woken), 6) |
| 1423 |
--- |
| 1424 |
> for i in range(6): |
| 1425 |
> woken.acquire() |
| 1426 |
> self.assertReturnsIfImplemented(0, get_value, woken) |
| 1427 |
1758a1756,1759 |
| 1428 |
> for w in workers: |
| 1429 |
> # NOTE: join_process and join_thread are the same |
| 1430 |
> threading_helper.join_thread(w) |
| 1431 |
> |
| 1432 |
1764a1766 |
| 1433 |
> workers = [] |
| 1434 |
1769c1771 |
| 1435 |
< self.addCleanup(p.join) |
| 1436 |
--- |
| 1437 |
> workers.append(p) |
| 1438 |
1774c1776 |
| 1439 |
< self.addCleanup(t.join) |
| 1440 |
--- |
| 1441 |
> workers.append(t) |
| 1442 |
1808a1811,1814 |
| 1443 |
> for w in workers: |
| 1444 |
> # NOTE: join_process and join_thread are the same |
| 1445 |
> threading_helper.join_thread(w) |
| 1446 |
> |
| 1447 |
6443a6450,6593 |
| 1448 |
> @classmethod |
| 1449 |
> def _test_set_operator_symbols(cls, obj): |
| 1450 |
> case = unittest.TestCase() |
| 1451 |
> obj.update(['a', 'b', 'c']) |
| 1452 |
> case.assertEqual(len(obj), 3) |
| 1453 |
> case.assertIn('a', obj) |
| 1454 |
> case.assertNotIn('d', obj) |
| 1455 |
> result = obj | {'d', 'e'} |
| 1456 |
> case.assertSetEqual(result, {'a', 'b', 'c', 'd', 'e'}) |
| 1457 |
> result = {'d', 'e'} | obj |
| 1458 |
> case.assertSetEqual(result, {'a', 'b', 'c', 'd', 'e'}) |
| 1459 |
> obj |= {'d', 'e'} |
| 1460 |
> case.assertSetEqual(obj, {'a', 'b', 'c', 'd', 'e'}) |
| 1461 |
> case.assertIsInstance(obj, multiprocessing.managers.SetProxy) |
| 1462 |
> |
| 1463 |
> obj.clear() |
| 1464 |
> obj.update(['a', 'b', 'c']) |
| 1465 |
> result = {'a', 'b', 'd'} - obj |
| 1466 |
> case.assertSetEqual(result, {'d'}) |
| 1467 |
> result = obj - {'a', 'b'} |
| 1468 |
> case.assertSetEqual(result, {'c'}) |
| 1469 |
> obj -= {'a', 'b'} |
| 1470 |
> case.assertSetEqual(obj, {'c'}) |
| 1471 |
> case.assertIsInstance(obj, multiprocessing.managers.SetProxy) |
| 1472 |
> |
| 1473 |
> obj.clear() |
| 1474 |
> obj.update(['a', 'b', 'c']) |
| 1475 |
> result = {'b', 'c', 'd'} ^ obj |
| 1476 |
> case.assertSetEqual(result, {'a', 'd'}) |
| 1477 |
> result = obj ^ {'b', 'c', 'd'} |
| 1478 |
> case.assertSetEqual(result, {'a', 'd'}) |
| 1479 |
> obj ^= {'b', 'c', 'd'} |
| 1480 |
> case.assertSetEqual(obj, {'a', 'd'}) |
| 1481 |
> case.assertIsInstance(obj, multiprocessing.managers.SetProxy) |
| 1482 |
> |
| 1483 |
> obj.clear() |
| 1484 |
> obj.update(['a', 'b', 'c']) |
| 1485 |
> result = obj & {'b', 'c', 'd'} |
| 1486 |
> case.assertSetEqual(result, {'b', 'c'}) |
| 1487 |
> result = {'b', 'c', 'd'} & obj |
| 1488 |
> case.assertSetEqual(result, {'b', 'c'}) |
| 1489 |
> obj &= {'b', 'c', 'd'} |
| 1490 |
> case.assertSetEqual(obj, {'b', 'c'}) |
| 1491 |
> case.assertIsInstance(obj, multiprocessing.managers.SetProxy) |
| 1492 |
> |
| 1493 |
> obj.clear() |
| 1494 |
> obj.update(['a', 'b', 'c']) |
| 1495 |
> case.assertSetEqual(set(obj), {'a', 'b', 'c'}) |
| 1496 |
> |
| 1497 |
> @classmethod |
| 1498 |
> def _test_set_operator_methods(cls, obj): |
| 1499 |
> case = unittest.TestCase() |
| 1500 |
> obj.add('d') |
| 1501 |
> case.assertIn('d', obj) |
| 1502 |
> |
| 1503 |
> obj.clear() |
| 1504 |
> obj.update(['a', 'b', 'c']) |
| 1505 |
> copy_obj = obj.copy() |
| 1506 |
> case.assertSetEqual(copy_obj, obj) |
| 1507 |
> obj.remove('a') |
| 1508 |
> case.assertNotIn('a', obj) |
| 1509 |
> case.assertRaises(KeyError, obj.remove, 'a') |
| 1510 |
> |
| 1511 |
> obj.clear() |
| 1512 |
> obj.update(['a']) |
| 1513 |
> obj.discard('a') |
| 1514 |
> case.assertNotIn('a', obj) |
| 1515 |
> obj.discard('a') |
| 1516 |
> case.assertNotIn('a', obj) |
| 1517 |
> obj.update(['a']) |
| 1518 |
> popped = obj.pop() |
| 1519 |
> case.assertNotIn(popped, obj) |
| 1520 |
> |
| 1521 |
> obj.clear() |
| 1522 |
> obj.update(['a', 'b', 'c']) |
| 1523 |
> result = obj.intersection({'b', 'c', 'd'}) |
| 1524 |
> case.assertSetEqual(result, {'b', 'c'}) |
| 1525 |
> obj.intersection_update({'b', 'c', 'd'}) |
| 1526 |
> case.assertSetEqual(obj, {'b', 'c'}) |
| 1527 |
> |
| 1528 |
> obj.clear() |
| 1529 |
> obj.update(['a', 'b', 'c']) |
| 1530 |
> result = obj.difference({'a', 'b'}) |
| 1531 |
> case.assertSetEqual(result, {'c'}) |
| 1532 |
> obj.difference_update({'a', 'b'}) |
| 1533 |
> case.assertSetEqual(obj, {'c'}) |
| 1534 |
> |
| 1535 |
> obj.clear() |
| 1536 |
> obj.update(['a', 'b', 'c']) |
| 1537 |
> result = obj.symmetric_difference({'b', 'c', 'd'}) |
| 1538 |
> case.assertSetEqual(result, {'a', 'd'}) |
| 1539 |
> obj.symmetric_difference_update({'b', 'c', 'd'}) |
| 1540 |
> case.assertSetEqual(obj, {'a', 'd'}) |
| 1541 |
> |
| 1542 |
> @classmethod |
| 1543 |
> def _test_set_comparisons(cls, obj): |
| 1544 |
> case = unittest.TestCase() |
| 1545 |
> obj.update(['a', 'b', 'c']) |
| 1546 |
> result = obj.union({'d', 'e'}) |
| 1547 |
> case.assertSetEqual(result, {'a', 'b', 'c', 'd', 'e'}) |
| 1548 |
> case.assertTrue(obj.isdisjoint({'d', 'e'})) |
| 1549 |
> case.assertFalse(obj.isdisjoint({'a', 'd'})) |
| 1550 |
> |
| 1551 |
> case.assertTrue(obj.issubset({'a', 'b', 'c', 'd'})) |
| 1552 |
> case.assertFalse(obj.issubset({'a', 'b'})) |
| 1553 |
> case.assertLess(obj, {'a', 'b', 'c', 'd'}) |
| 1554 |
> case.assertLessEqual(obj, {'a', 'b', 'c'}) |
| 1555 |
> |
| 1556 |
> case.assertTrue(obj.issuperset({'a', 'b'})) |
| 1557 |
> case.assertFalse(obj.issuperset({'a', 'b', 'd'})) |
| 1558 |
> case.assertGreater(obj, {'a'}) |
| 1559 |
> case.assertGreaterEqual(obj, {'a', 'b'}) |
| 1560 |
> |
| 1561 |
> def test_set(self): |
| 1562 |
> o = self.manager.set() |
| 1563 |
> self.run_worker(self._test_set_operator_symbols, o) |
| 1564 |
> o = self.manager.set() |
| 1565 |
> self.run_worker(self._test_set_operator_methods, o) |
| 1566 |
> o = self.manager.set() |
| 1567 |
> self.run_worker(self._test_set_comparisons, o) |
| 1568 |
> |
| 1569 |
> def test_set_init(self): |
| 1570 |
> o = self.manager.set({'a', 'b', 'c'}) |
| 1571 |
> self.assertSetEqual(o, {'a', 'b', 'c'}) |
| 1572 |
> o = self.manager.set(["a", "b", "c"]) |
| 1573 |
> self.assertSetEqual(o, {"a", "b", "c"}) |
| 1574 |
> o = self.manager.set({"a": 1, "b": 2, "c": 3}) |
| 1575 |
> self.assertSetEqual(o, {"a", "b", "c"}) |
| 1576 |
> self.assertRaises(RemoteError, self.manager.set, 1234) |
| 1577 |
> |
| 1578 |
> def test_set_contain_all_method(self): |
| 1579 |
> o = self.manager.set() |
| 1580 |
> set_methods = { |
| 1581 |
> '__and__', '__class_getitem__', '__contains__', '__iand__', '__ior__', |
| 1582 |
> '__isub__', '__iter__', '__ixor__', '__len__', '__or__', '__rand__', |
| 1583 |
> '__ror__', '__rsub__', '__rxor__', '__sub__', '__xor__', |
| 1584 |
> '__ge__', '__gt__', '__le__', '__lt__', |
| 1585 |
> 'add', 'clear', 'copy', 'difference', 'difference_update', 'discard', |
| 1586 |
> 'intersection', 'intersection_update', 'isdisjoint', 'issubset', |
| 1587 |
> 'issuperset', 'pop', 'remove', 'symmetric_difference', |
| 1588 |
> 'symmetric_difference_update', 'union', 'update', |
| 1589 |
> } |
| 1590 |
> self.assertLessEqual(set_methods, set(dir(o))) |
| 1591 |
> |
| 1592 |
# ---------------------------------------------------------------------- |
| 1593 |
diff Python-3.14.0a6/Modules/_multiprocessing/semaphore.c Python-3.14.0a7/Modules/_multiprocessing/semaphore.c |
| 1594 |
68c68 |
| 1595 |
< _GetSemaphoreValue(HANDLE handle, long *value) |
| 1596 |
--- |
| 1597 |
> _GetSemaphoreValue(HANDLE handle, int *value) |
| 1598 |
diff Python-3.14.0a6/Modules/_multiprocessing/clinic/semaphore.c.h Python-3.14.0a7/Modules/_multiprocessing/clinic/semaphore.c.h |
| 1599 |
36a37 |
| 1600 |
> Py_hash_t ob_hash; |
| 1601 |
39a41 |
| 1602 |
> .ob_hash = -1, |
| 1603 |
142a145 |
| 1604 |
> Py_hash_t ob_hash; |
| 1605 |
145a149 |
| 1606 |
> .ob_hash = -1, |
| 1607 |
239a244 |
| 1608 |
> Py_hash_t ob_hash; |
| 1609 |
242a248 |
| 1610 |
> .ob_hash = -1, |
| 1611 |
579c585 |
| 1612 |
< /*[clinic end generated code: output=dddd8e989525f565 input=a9049054013a1b77]*/ |
| 1613 |
--- |
| 1614 |
> /*[clinic end generated code: output=d1e349d4ee3d4bbf input=a9049054013a1b77]*/ |
| 1615 |
diff Python-3.14.0a6/Lib/multiprocessing/connection.py Python-3.14.0a7/Lib/multiprocessing/connection.py |
| 1616 |
324a325,327 |
| 1617 |
> |
| 1618 |
> sentinel = object() |
| 1619 |
> return_value = sentinel |
| 1620 |
326,329c329,344 |
| 1621 |
< if err == _winapi.ERROR_IO_PENDING: |
| 1622 |
< waitres = _winapi.WaitForMultipleObjects( |
| 1623 |
< [ov.event], False, INFINITE) |
| 1624 |
< assert waitres == WAIT_OBJECT_0 |
| 1625 |
--- |
| 1626 |
> try: |
| 1627 |
> if err == _winapi.ERROR_IO_PENDING: |
| 1628 |
> waitres = _winapi.WaitForMultipleObjects( |
| 1629 |
> [ov.event], False, INFINITE) |
| 1630 |
> assert waitres == WAIT_OBJECT_0 |
| 1631 |
> except: |
| 1632 |
> ov.cancel() |
| 1633 |
> raise |
| 1634 |
> finally: |
| 1635 |
> nread, err = ov.GetOverlappedResult(True) |
| 1636 |
> if err == 0: |
| 1637 |
> f = io.BytesIO() |
| 1638 |
> f.write(ov.getbuffer()) |
| 1639 |
> return_value = f |
| 1640 |
> elif err == _winapi.ERROR_MORE_DATA: |
| 1641 |
> return_value = self._get_more_data(ov, maxsize) |
| 1642 |
331,340c346,350 |
| 1643 |
< ov.cancel() |
| 1644 |
< raise |
| 1645 |
< finally: |
| 1646 |
< nread, err = ov.GetOverlappedResult(True) |
| 1647 |
< if err == 0: |
| 1648 |
< f = io.BytesIO() |
| 1649 |
< f.write(ov.getbuffer()) |
| 1650 |
< return f |
| 1651 |
< elif err == _winapi.ERROR_MORE_DATA: |
| 1652 |
< return self._get_more_data(ov, maxsize) |
| 1653 |
--- |
| 1654 |
> if return_value is sentinel: |
| 1655 |
> raise |
| 1656 |
> |
| 1657 |
> if return_value is not sentinel: |
| 1658 |
> return return_value |
| 1659 |
diff Python-3.14.0a6/Lib/multiprocessing/managers.py Python-3.14.0a7/Lib/multiprocessing/managers.py |
| 1660 |
1062c1062 |
| 1661 |
< _exposed_ = ('acquire', 'release') |
| 1662 |
--- |
| 1663 |
> _exposed_ = ('acquire', 'release', 'locked') |
| 1664 |
1067a1068,1069 |
| 1665 |
> def locked(self): |
| 1666 |
> return self._callmethod('locked') |
| 1667 |
1075c1077 |
| 1668 |
< _exposed_ = ('acquire', 'release', 'wait', 'notify', 'notify_all') |
| 1669 |
--- |
| 1670 |
> _exposed_ = ('acquire', 'release', 'locked', 'wait', 'notify', 'notify_all') |
| 1671 |
diff Python-3.14.0a6/Lib/multiprocessing/resource_tracker.py Python-3.14.0a7/Lib/multiprocessing/resource_tracker.py |
| 1672 |
78,86c78,94 |
| 1673 |
< def _stop(self): |
| 1674 |
< with self._lock: |
| 1675 |
< # This should not happen (_stop() isn't called by a finalizer) |
| 1676 |
< # but we check for it anyway. |
| 1677 |
< if self._lock._recursion_count() > 1: |
| 1678 |
< return self._reentrant_call_error() |
| 1679 |
< if self._fd is None: |
| 1680 |
< # not running |
| 1681 |
< return |
| 1682 |
--- |
| 1683 |
> def __del__(self): |
| 1684 |
> # making sure child processess are cleaned before ResourceTracker |
| 1685 |
> # gets destructed. |
| 1686 |
> # see https://github.com/python/cpython/issues/88887 |
| 1687 |
> self._stop(use_blocking_lock=False) |
| 1688 |
> |
| 1689 |
> def _stop(self, use_blocking_lock=True): |
| 1690 |
> if use_blocking_lock: |
| 1691 |
> with self._lock: |
| 1692 |
> self._stop_locked() |
| 1693 |
> else: |
| 1694 |
> acquired = self._lock.acquire(blocking=False) |
| 1695 |
> try: |
| 1696 |
> self._stop_locked() |
| 1697 |
> finally: |
| 1698 |
> if acquired: |
| 1699 |
> self._lock.release() |
| 1700 |
88,90c96,114 |
| 1701 |
< # closing the "alive" file descriptor stops main() |
| 1702 |
< os.close(self._fd) |
| 1703 |
< self._fd = None |
| 1704 |
--- |
| 1705 |
> def _stop_locked( |
| 1706 |
> self, |
| 1707 |
> close=os.close, |
| 1708 |
> waitpid=os.waitpid, |
| 1709 |
> waitstatus_to_exitcode=os.waitstatus_to_exitcode, |
| 1710 |
> ): |
| 1711 |
> # This shouldn't happen (it might when called by a finalizer) |
| 1712 |
> # so we check for it anyway. |
| 1713 |
> if self._lock._recursion_count() > 1: |
| 1714 |
> return self._reentrant_call_error() |
| 1715 |
> if self._fd is None: |
| 1716 |
> # not running |
| 1717 |
> return |
| 1718 |
> if self._pid is None: |
| 1719 |
> return |
| 1720 |
> |
| 1721 |
> # closing the "alive" file descriptor stops main() |
| 1722 |
> close(self._fd) |
| 1723 |
> self._fd = None |
| 1724 |
92c116 |
| 1725 |
< _, status = os.waitpid(self._pid, 0) |
| 1726 |
--- |
| 1727 |
> _, status = waitpid(self._pid, 0) |
| 1728 |
94c118 |
| 1729 |
< self._pid = None |
| 1730 |
--- |
| 1731 |
> self._pid = None |
| 1732 |
96,100c120,124 |
| 1733 |
< try: |
| 1734 |
< self._exitcode = os.waitstatus_to_exitcode(status) |
| 1735 |
< except ValueError: |
| 1736 |
< # os.waitstatus_to_exitcode may raise an exception for invalid values |
| 1737 |
< self._exitcode = None |
| 1738 |
--- |
| 1739 |
> try: |
| 1740 |
> self._exitcode = waitstatus_to_exitcode(status) |
| 1741 |
> except ValueError: |
| 1742 |
> # os.waitstatus_to_exitcode may raise an exception for invalid values |
| 1743 |
> self._exitcode = None |
| 1744 |
diff Python-3.14.0a6/Lib/multiprocessing/synchronize.py Python-3.14.0a7/Lib/multiprocessing/synchronize.py |
| 1745 |
92a93,95 |
| 1746 |
> def locked(self): |
| 1747 |
> return self._semlock._count() != 0 |
| 1748 |
> |
| 1749 |
diff Python-3.14.0a6/Lib/test/_test_multiprocessing.py Python-3.14.0a7/Lib/test/_test_multiprocessing.py |
| 1750 |
1488a1489 |
| 1751 |
> self.assertTrue(lock.locked()) |
| 1752 |
1490a1492 |
| 1753 |
> self.assertFalse(lock.locked()) |
| 1754 |
1551a1554 |
| 1755 |
> self.assertTrue(lock.locked()) |
| 1756 |
1554a1558 |
| 1757 |
> self.assertTrue(lock.locked()) |
| 1758 |
1556a1561 |
| 1759 |
> self.assertFalse(lock.locked()) |
| 1760 |
1560,1561c1565,1570 |
| 1761 |
< with self.Lock(): |
| 1762 |
< pass |
| 1763 |
--- |
| 1764 |
> with self.Lock() as locked: |
| 1765 |
> self.assertTrue(locked) |
| 1766 |
> |
| 1767 |
> def test_rlock_context(self): |
| 1768 |
> with self.RLock() as locked: |
| 1769 |
> self.assertTrue(locked) |
| 1770 |
6256a6266 |
| 1771 |
> obj.locked() |
| 1772 |
6267a6278 |
| 1773 |
> obj.locked() |
| 1774 |
6269c6280 |
| 1775 |
< def test_rlock(self, lname="Lock"): |
| 1776 |
--- |
| 1777 |
> def test_rlock(self, lname="RLock"): |
| 1778 |
# ---------------------------------------------------------------------- |
| 1779 |
diff Python-3.14.0a7/Lib/multiprocessing/popen_fork.py Python-3.14.0b1/Lib/multiprocessing/popen_fork.py |
| 1780 |
56a57,59 |
| 1781 |
> def interrupt(self): |
| 1782 |
> self._send_signal(signal.SIGINT) |
| 1783 |
> |
| 1784 |
diff Python-3.14.0a7/Lib/multiprocessing/process.py Python-3.14.0b1/Lib/multiprocessing/process.py |
| 1785 |
127a128,134 |
| 1786 |
> def interrupt(self): |
| 1787 |
> ''' |
| 1788 |
> Terminate process; sends SIGINT signal |
| 1789 |
> ''' |
| 1790 |
> self._check_closed() |
| 1791 |
> self._popen.interrupt() |
| 1792 |
> |
| 1793 |
diff Python-3.14.0a7/Lib/multiprocessing/synchronize.py Python-3.14.0b1/Lib/multiprocessing/synchronize.py |
| 1794 |
94c94 |
| 1795 |
< return self._semlock._count() != 0 |
| 1796 |
--- |
| 1797 |
> return self._semlock._is_zero() |
| 1798 |
diff Python-3.14.0a7/Lib/test/_test_multiprocessing.py Python-3.14.0b1/Lib/test/_test_multiprocessing.py |
| 1799 |
515a516,520 |
| 1800 |
> def _sleep_no_int_handler(cls): |
| 1801 |
> signal.signal(signal.SIGINT, signal.SIG_DFL) |
| 1802 |
> cls._sleep_some() |
| 1803 |
> |
| 1804 |
> @classmethod |
| 1805 |
519c524 |
| 1806 |
< def _kill_process(self, meth): |
| 1807 |
--- |
| 1808 |
> def _kill_process(self, meth, target=None): |
| 1809 |
523c528 |
| 1810 |
< p = self.Process(target=self._sleep_some) |
| 1811 |
--- |
| 1812 |
> p = self.Process(target=target or self._sleep_some) |
| 1813 |
569a575,587 |
| 1814 |
> @unittest.skipIf(os.name == 'nt', "POSIX only") |
| 1815 |
> def test_interrupt(self): |
| 1816 |
> exitcode = self._kill_process(multiprocessing.Process.interrupt) |
| 1817 |
> self.assertEqual(exitcode, 1) |
| 1818 |
> # exit code 1 is hard-coded for uncaught exceptions |
| 1819 |
> # (KeyboardInterrupt in this case) |
| 1820 |
> # in multiprocessing.BaseProcess._bootstrap |
| 1821 |
> |
| 1822 |
> @unittest.skipIf(os.name == 'nt', "POSIX only") |
| 1823 |
> def test_interrupt_no_handler(self): |
| 1824 |
> exitcode = self._kill_process(multiprocessing.Process.interrupt, target=self._sleep_no_int_handler) |
| 1825 |
> self.assertEqual(exitcode, -signal.SIGINT) |
| 1826 |
> |
| 1827 |
1494a1513,1534 |
| 1828 |
> @classmethod |
| 1829 |
> def _test_lock_locked_2processes(cls, lock, event, res): |
| 1830 |
> lock.acquire() |
| 1831 |
> res.value = lock.locked() |
| 1832 |
> event.set() |
| 1833 |
> |
| 1834 |
> @unittest.skipUnless(HAS_SHAREDCTYPES, 'needs sharedctypes') |
| 1835 |
> def test_lock_locked_2processes(self): |
| 1836 |
> if self.TYPE != 'processes': |
| 1837 |
> self.skipTest('test not appropriate for {}'.format(self.TYPE)) |
| 1838 |
> |
| 1839 |
> lock = self.Lock() |
| 1840 |
> event = self.Event() |
| 1841 |
> res = self.Value('b', 0) |
| 1842 |
> p = self.Process(target=self._test_lock_locked_2processes, |
| 1843 |
> args=(lock, event, res)) |
| 1844 |
> p.start() |
| 1845 |
> event.wait() |
| 1846 |
> self.assertTrue(lock.locked()) |
| 1847 |
> self.assertTrue(res.value) |
| 1848 |
> p.join() |
| 1849 |
> |
| 1850 |
1563a1604,1620 |
| 1851 |
> @unittest.skipUnless(HAS_SHAREDCTYPES, 'needs sharedctypes') |
| 1852 |
> def test_rlock_locked_2processes(self): |
| 1853 |
> if self.TYPE != 'processes': |
| 1854 |
> self.skipTest('test not appropriate for {}'.format(self.TYPE)) |
| 1855 |
> |
| 1856 |
> rlock = self.RLock() |
| 1857 |
> event = self.Event() |
| 1858 |
> res = self.Value('b', 0) |
| 1859 |
> # target is the same as for the test_lock_locked_2processes test. |
| 1860 |
> p = self.Process(target=self._test_lock_locked_2processes, |
| 1861 |
> args=(rlock, event, res)) |
| 1862 |
> p.start() |
| 1863 |
> event.wait() |
| 1864 |
> self.assertTrue(rlock.locked()) |
| 1865 |
> self.assertTrue(res.value) |
| 1866 |
> p.join() |
| 1867 |
> |
| 1868 |
# ---------------------------------------------------------------------- |
| 1869 |
diff Python-3.14.0b1/Lib/multiprocessing/connection.py Python-3.14.0b2/Lib/multiprocessing/connection.py |
| 1870 |
79c79 |
| 1871 |
< return tempfile.mktemp(prefix='listener-', dir=util.get_temp_dir()) |
| 1872 |
--- |
| 1873 |
> return tempfile.mktemp(prefix='sock-', dir=util.get_temp_dir()) |
| 1874 |
diff Python-3.14.0b1/Lib/multiprocessing/context.py Python-3.14.0b2/Lib/multiprocessing/context.py |
| 1875 |
148c148 |
| 1876 |
< if sys.platform == 'win32' and getattr(sys, 'frozen', False): |
| 1877 |
--- |
| 1878 |
> if self.get_start_method() == 'spawn' and getattr(sys, 'frozen', False): |
| 1879 |
diff Python-3.14.0b1/Lib/multiprocessing/util.py Python-3.14.0b2/Lib/multiprocessing/util.py |
| 1880 |
22c22 |
| 1881 |
< 'sub_debug', 'debug', 'info', 'sub_warning', 'get_logger', |
| 1882 |
--- |
| 1883 |
> 'sub_debug', 'debug', 'info', 'sub_warning', 'warn', 'get_logger', |
| 1884 |
36a37 |
| 1885 |
> WARNING = 30 |
| 1886 |
55a57,60 |
| 1887 |
> def warn(msg, *args): |
| 1888 |
> if _logger: |
| 1889 |
> _logger.log(WARNING, msg, *args, stacklevel=2) |
| 1890 |
> |
| 1891 |
123a129,143 |
| 1892 |
> # Maximum length of a socket file path is usually between 92 and 108 [1], |
| 1893 |
> # but Linux is known to use a size of 108 [2]. BSD-based systems usually |
| 1894 |
> # use a size of 104 or 108 and Windows does not create AF_UNIX sockets. |
| 1895 |
> # |
| 1896 |
> # [1]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_un.h.html |
| 1897 |
> # [2]: https://man7.org/linux/man-pages/man7/unix.7.html. |
| 1898 |
> |
| 1899 |
> if sys.platform == 'linux': |
| 1900 |
> _SUN_PATH_MAX = 108 |
| 1901 |
> elif sys.platform.startswith(('openbsd', 'freebsd')): |
| 1902 |
> _SUN_PATH_MAX = 104 |
| 1903 |
> else: |
| 1904 |
> # On Windows platforms, we do not create AF_UNIX sockets. |
| 1905 |
> _SUN_PATH_MAX = None if os.name == 'nt' else 92 |
| 1906 |
> |
| 1907 |
132a153,206 |
| 1908 |
> def _get_base_temp_dir(tempfile): |
| 1909 |
> """Get a temporary directory where socket files will be created. |
| 1910 |
> |
| 1911 |
> To prevent additional imports, pass a pre-imported 'tempfile' module. |
| 1912 |
> """ |
| 1913 |
> if os.name == 'nt': |
| 1914 |
> return None |
| 1915 |
> # Most of the time, the default temporary directory is /tmp. Thus, |
| 1916 |
> # listener sockets files "$TMPDIR/pymp-XXXXXXXX/sock-XXXXXXXX" do |
| 1917 |
> # not have a path length exceeding SUN_PATH_MAX. |
| 1918 |
> # |
| 1919 |
> # If users specify their own temporary directory, we may be unable |
| 1920 |
> # to create those files. Therefore, we fall back to the system-wide |
| 1921 |
> # temporary directory /tmp, assumed to exist on POSIX systems. |
| 1922 |
> # |
| 1923 |
> # See https://github.com/python/cpython/issues/132124. |
| 1924 |
> base_tempdir = tempfile.gettempdir() |
| 1925 |
> # Files created in a temporary directory are suffixed by a string |
| 1926 |
> # generated by tempfile._RandomNameSequence, which, by design, |
| 1927 |
> # is 8 characters long. |
| 1928 |
> # |
| 1929 |
> # Thus, the length of socket filename will be: |
| 1930 |
> # |
| 1931 |
> # len(base_tempdir + '/pymp-XXXXXXXX' + '/sock-XXXXXXXX') |
| 1932 |
> sun_path_len = len(base_tempdir) + 14 + 14 |
| 1933 |
> if sun_path_len <= _SUN_PATH_MAX: |
| 1934 |
> return base_tempdir |
| 1935 |
> # Fallback to the default system-wide temporary directory. |
| 1936 |
> # This ignores user-defined environment variables. |
| 1937 |
> # |
| 1938 |
> # On POSIX systems, /tmp MUST be writable by any application [1]. |
| 1939 |
> # We however emit a warning if this is not the case to prevent |
| 1940 |
> # obscure errors later in the execution. |
| 1941 |
> # |
| 1942 |
> # On some legacy systems, /var/tmp and /usr/tmp can be present |
| 1943 |
> # and will be used instead. |
| 1944 |
> # |
| 1945 |
> # [1]: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s18.html |
| 1946 |
> dirlist = ['/tmp', '/var/tmp', '/usr/tmp'] |
| 1947 |
> try: |
| 1948 |
> base_system_tempdir = tempfile._get_default_tempdir(dirlist) |
| 1949 |
> except FileNotFoundError: |
| 1950 |
> warn("Process-wide temporary directory %s will not be usable for " |
| 1951 |
> "creating socket files and no usable system-wide temporary " |
| 1952 |
> "directory was found in %s", base_tempdir, dirlist) |
| 1953 |
> # At this point, the system-wide temporary directory is not usable |
| 1954 |
> # but we may assume that the user-defined one is, even if we will |
| 1955 |
> # not be able to write socket files out there. |
| 1956 |
> return base_tempdir |
| 1957 |
> warn("Ignoring user-defined temporary directory: %s", base_tempdir) |
| 1958 |
> # at most max(map(len, dirlist)) + 14 + 14 = 36 characters |
| 1959 |
> assert len(base_system_tempdir) + 14 + 14 <= _SUN_PATH_MAX |
| 1960 |
> return base_system_tempdir |
| 1961 |
> |
| 1962 |
138c212,213 |
| 1963 |
< tempdir = tempfile.mkdtemp(prefix='pymp-') |
| 1964 |
--- |
| 1965 |
> base_tempdir = _get_base_temp_dir(tempfile) |
| 1966 |
> tempdir = tempfile.mkdtemp(prefix='pymp-', dir=base_tempdir) |
| 1967 |
diff Python-3.14.0b1/Lib/test/_test_multiprocessing.py Python-3.14.0b2/Lib/test/_test_multiprocessing.py |
| 1968 |
516c516,521 |
| 1969 |
< def _sleep_no_int_handler(cls): |
| 1970 |
--- |
| 1971 |
> def _sleep_some_event(cls, event): |
| 1972 |
> event.set() |
| 1973 |
> time.sleep(100) |
| 1974 |
> |
| 1975 |
> @classmethod |
| 1976 |
> def _sleep_no_int_handler(cls, event): |
| 1977 |
518c523 |
| 1978 |
< cls._sleep_some() |
| 1979 |
--- |
| 1980 |
> cls._sleep_some_event(event) |
| 1981 |
528c533,536 |
| 1982 |
< p = self.Process(target=target or self._sleep_some) |
| 1983 |
--- |
| 1984 |
> event = self.Event() |
| 1985 |
> if not target: |
| 1986 |
> target = self._sleep_some_event |
| 1987 |
> p = self.Process(target=target, args=(event,)) |
| 1988 |
546,547c554,558 |
| 1989 |
< # XXX maybe terminating too soon causes the problems on Gentoo... |
| 1990 |
< time.sleep(1) |
| 1991 |
--- |
| 1992 |
> timeout = support.SHORT_TIMEOUT |
| 1993 |
> if not event.wait(timeout): |
| 1994 |
> p.terminate() |
| 1995 |
> p.join() |
| 1996 |
> self.fail(f"event not signaled in {timeout} seconds") |
| 1997 |
6823a6835,6856 |
| 1998 |
> def test_forked_thread_not_started(self): |
| 1999 |
> # gh-134381: Ensure that a thread that has not been started yet in |
| 2000 |
> # the parent process can be started within a forked child process. |
| 2001 |
> |
| 2002 |
> if multiprocessing.get_start_method() != "fork": |
| 2003 |
> self.skipTest("fork specific test") |
| 2004 |
> |
| 2005 |
> q = multiprocessing.Queue() |
| 2006 |
> t = threading.Thread(target=lambda: q.put("done"), daemon=True) |
| 2007 |
> |
| 2008 |
> def child(): |
| 2009 |
> t.start() |
| 2010 |
> t.join() |
| 2011 |
> |
| 2012 |
> p = multiprocessing.Process(target=child) |
| 2013 |
> p.start() |
| 2014 |
> p.join(support.SHORT_TIMEOUT) |
| 2015 |
> |
| 2016 |
> self.assertEqual(p.exitcode, 0) |
| 2017 |
> self.assertEqual(q.get_nowait(), "done") |
| 2018 |
> close_queue(q) |
| 2019 |
> |
| 2020 |
# ---------------------------------------------------------------------- |
| 2021 |
diff Python-3.14.0b2/Lib/multiprocessing/forkserver.py Python-3.14.0b4/Lib/multiprocessing/forkserver.py |
| 2022 |
224a225,228 |
| 2023 |
> # gh-135335: flush stdout/stderr in case any of the preloaded modules |
| 2024 |
> # wrote to them, otherwise children might inherit buffered data |
| 2025 |
> util._flush_std_streams() |
| 2026 |
> |
| 2027 |
diff Python-3.14.0b2/Lib/test/_test_multiprocessing.py Python-3.14.0b4/Lib/test/_test_multiprocessing.py |
| 2028 |
6791a6792,6820 |
| 2029 |
> def test_std_streams_flushed_after_preload(self): |
| 2030 |
> # gh-135335: Check fork server flushes standard streams after |
| 2031 |
> # preloading modules |
| 2032 |
> if multiprocessing.get_start_method() != "forkserver": |
| 2033 |
> self.skipTest("forkserver specific test") |
| 2034 |
> |
| 2035 |
> # Create a test module in the temporary directory on the child's path |
| 2036 |
> # TODO: This can all be simplified once gh-126631 is fixed and we can |
| 2037 |
> # use __main__ instead of a module. |
| 2038 |
> dirname = os.path.join(self._temp_dir, 'preloaded_module') |
| 2039 |
> init_name = os.path.join(dirname, '__init__.py') |
| 2040 |
> os.mkdir(dirname) |
| 2041 |
> with open(init_name, "w") as f: |
| 2042 |
> cmd = '''if 1: |
| 2043 |
> import sys |
| 2044 |
> print('stderr', end='', file=sys.stderr) |
| 2045 |
> print('stdout', end='', file=sys.stdout) |
| 2046 |
> ''' |
| 2047 |
> f.write(cmd) |
| 2048 |
> |
| 2049 |
> name = os.path.join(os.path.dirname(__file__), 'mp_preload_flush.py') |
| 2050 |
> env = {'PYTHONPATH': self._temp_dir} |
| 2051 |
> _, out, err = test.support.script_helper.assert_python_ok(name, **env) |
| 2052 |
> |
| 2053 |
> # Check stderr first, as it is more likely to be useful to see in the |
| 2054 |
> # event of a failure. |
| 2055 |
> self.assertEqual(err.decode().rstrip(), 'stderr') |
| 2056 |
> self.assertEqual(out.decode().rstrip(), 'stdout') |
| 2057 |
> |
| 2058 |
# ---------------------------------------------------------------------- |
| 2059 |
diff Python-3.14.0b4/Lib/multiprocessing/resource_tracker.py Python-3.14.0rc1/Lib/multiprocessing/resource_tracker.py |
| 2060 |
50,55c50,51 |
| 2061 |
< _CLEANUP_FUNCS.update({ |
| 2062 |
< 'semaphore': _multiprocessing.sem_unlink, |
| 2063 |
< }) |
| 2064 |
< _CLEANUP_FUNCS.update({ |
| 2065 |
< 'shared_memory': _posixshmem.shm_unlink, |
| 2066 |
< }) |
| 2067 |
--- |
| 2068 |
> _CLEANUP_FUNCS['semaphore'] = _multiprocessing.sem_unlink |
| 2069 |
> _CLEANUP_FUNCS['shared_memory'] = _posixshmem.shm_unlink |
| 2070 |
# ---------------------------------------------------------------------- |
| 2071 |
diff Python-3.14.0rc1/Lib/multiprocessing/forkserver.py Python-3.14.1/Lib/multiprocessing/forkserver.py |
| 2072 |
147a148 |
| 2073 |
> main_kws = {} |
| 2074 |
149d149 |
| 2075 |
< desired_keys = {'main_path', 'sys_path'} |
| 2076 |
151,153c151,154 |
| 2077 |
< main_kws = {x: y for x, y in data.items() if x in desired_keys} |
| 2078 |
< else: |
| 2079 |
< main_kws = {} |
| 2080 |
--- |
| 2081 |
> if 'sys_path' in data: |
| 2082 |
> main_kws['sys_path'] = data['sys_path'] |
| 2083 |
> if 'init_main_from_path' in data: |
| 2084 |
> main_kws['main_path'] = data['init_main_from_path'] |
| 2085 |
diff Python-3.14.0rc1/Lib/multiprocessing/popen_spawn_posix.py Python-3.14.1/Lib/multiprocessing/popen_spawn_posix.py |
| 2086 |
59a60,63 |
| 2087 |
> os.close(child_r) |
| 2088 |
> child_r = None |
| 2089 |
> os.close(child_w) |
| 2090 |
> child_w = None |
| 2091 |
diff Python-3.14.0rc1/Lib/multiprocessing/process.py Python-3.14.1/Lib/multiprocessing/process.py |
| 2092 |
80c80 |
| 2093 |
< def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, |
| 2094 |
--- |
| 2095 |
> def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, |
| 2096 |
92c92 |
| 2097 |
< self._kwargs = dict(kwargs) |
| 2098 |
--- |
| 2099 |
> self._kwargs = dict(kwargs) if kwargs else {} |
| 2100 |
diff Python-3.14.0rc1/Lib/multiprocessing/queues.py Python-3.14.1/Lib/multiprocessing/queues.py |
| 2101 |
124c124 |
| 2102 |
< return self._maxsize - self._sem._semlock._get_value() |
| 2103 |
--- |
| 2104 |
> return self._maxsize - self._sem.get_value() |
| 2105 |
diff Python-3.14.0rc1/Lib/multiprocessing/resource_tracker.py Python-3.14.1/Lib/multiprocessing/resource_tracker.py |
| 2106 |
17a18 |
| 2107 |
> import base64 |
| 2108 |
22a24,26 |
| 2109 |
> from collections import deque |
| 2110 |
> |
| 2111 |
> import json |
| 2112 |
64a69 |
| 2113 |
> self._reentrant_messages = deque() |
| 2114 |
101c106 |
| 2115 |
< return self._reentrant_call_error() |
| 2116 |
--- |
| 2117 |
> raise self._reentrant_call_error() |
| 2118 |
112c117,122 |
| 2119 |
< _, status = waitpid(self._pid, 0) |
| 2120 |
--- |
| 2121 |
> try: |
| 2122 |
> _, status = waitpid(self._pid, 0) |
| 2123 |
> except ChildProcessError: |
| 2124 |
> self._pid = None |
| 2125 |
> self._exitcode = None |
| 2126 |
> return |
| 2127 |
130a141,213 |
| 2128 |
> return self._ensure_running_and_write() |
| 2129 |
> |
| 2130 |
> def _teardown_dead_process(self): |
| 2131 |
> os.close(self._fd) |
| 2132 |
> |
| 2133 |
> # Clean-up to avoid dangling processes. |
| 2134 |
> try: |
| 2135 |
> # _pid can be None if this process is a child from another |
| 2136 |
> # python process, which has started the resource_tracker. |
| 2137 |
> if self._pid is not None: |
| 2138 |
> os.waitpid(self._pid, 0) |
| 2139 |
> except ChildProcessError: |
| 2140 |
> # The resource_tracker has already been terminated. |
| 2141 |
> pass |
| 2142 |
> self._fd = None |
| 2143 |
> self._pid = None |
| 2144 |
> self._exitcode = None |
| 2145 |
> |
| 2146 |
> warnings.warn('resource_tracker: process died unexpectedly, ' |
| 2147 |
> 'relaunching. Some resources might leak.') |
| 2148 |
> |
| 2149 |
> def _launch(self): |
| 2150 |
> fds_to_pass = [] |
| 2151 |
> try: |
| 2152 |
> fds_to_pass.append(sys.stderr.fileno()) |
| 2153 |
> except Exception: |
| 2154 |
> pass |
| 2155 |
> r, w = os.pipe() |
| 2156 |
> try: |
| 2157 |
> fds_to_pass.append(r) |
| 2158 |
> # process will out live us, so no need to wait on pid |
| 2159 |
> exe = spawn.get_executable() |
| 2160 |
> args = [ |
| 2161 |
> exe, |
| 2162 |
> *util._args_from_interpreter_flags(), |
| 2163 |
> '-c', |
| 2164 |
> f'from multiprocessing.resource_tracker import main;main({r})', |
| 2165 |
> ] |
| 2166 |
> # bpo-33613: Register a signal mask that will block the signals. |
| 2167 |
> # This signal mask will be inherited by the child that is going |
| 2168 |
> # to be spawned and will protect the child from a race condition |
| 2169 |
> # that can make the child die before it registers signal handlers |
| 2170 |
> # for SIGINT and SIGTERM. The mask is unregistered after spawning |
| 2171 |
> # the child. |
| 2172 |
> prev_sigmask = None |
| 2173 |
> try: |
| 2174 |
> if _HAVE_SIGMASK: |
| 2175 |
> prev_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) |
| 2176 |
> pid = util.spawnv_passfds(exe, args, fds_to_pass) |
| 2177 |
> finally: |
| 2178 |
> if prev_sigmask is not None: |
| 2179 |
> signal.pthread_sigmask(signal.SIG_SETMASK, prev_sigmask) |
| 2180 |
> except: |
| 2181 |
> os.close(w) |
| 2182 |
> raise |
| 2183 |
> else: |
| 2184 |
> self._fd = w |
| 2185 |
> self._pid = pid |
| 2186 |
> finally: |
| 2187 |
> os.close(r) |
| 2188 |
> |
| 2189 |
> def _make_probe_message(self): |
| 2190 |
> """Return a JSON-encoded probe message.""" |
| 2191 |
> return ( |
| 2192 |
> json.dumps( |
| 2193 |
> {"cmd": "PROBE", "rtype": "noop"}, |
| 2194 |
> ensure_ascii=True, |
| 2195 |
> separators=(",", ":"), |
| 2196 |
> ) |
| 2197 |
> + "\n" |
| 2198 |
> ).encode("ascii") |
| 2199 |
> |
| 2200 |
> def _ensure_running_and_write(self, msg=None): |
| 2201 |
134c217,220 |
| 2202 |
< return self._reentrant_call_error() |
| 2203 |
--- |
| 2204 |
> if msg is None: |
| 2205 |
> raise self._reentrant_call_error() |
| 2206 |
> return self._reentrant_messages.append(msg) |
| 2207 |
> |
| 2208 |
137,143c223,226 |
| 2209 |
< if self._check_alive(): |
| 2210 |
< # => still alive |
| 2211 |
< return |
| 2212 |
< # => dead, launch it again |
| 2213 |
< os.close(self._fd) |
| 2214 |
< |
| 2215 |
< # Clean-up to avoid dangling processes. |
| 2216 |
--- |
| 2217 |
> if msg is None: |
| 2218 |
> to_send = self._make_probe_message() |
| 2219 |
> else: |
| 2220 |
> to_send = msg |
| 2221 |
145,154c228,231 |
| 2222 |
< # _pid can be None if this process is a child from another |
| 2223 |
< # python process, which has started the resource_tracker. |
| 2224 |
< if self._pid is not None: |
| 2225 |
< os.waitpid(self._pid, 0) |
| 2226 |
< except ChildProcessError: |
| 2227 |
< # The resource_tracker has already been terminated. |
| 2228 |
< pass |
| 2229 |
< self._fd = None |
| 2230 |
< self._pid = None |
| 2231 |
< self._exitcode = None |
| 2232 |
--- |
| 2233 |
> self._write(to_send) |
| 2234 |
> except OSError: |
| 2235 |
> self._teardown_dead_process() |
| 2236 |
> self._launch() |
| 2237 |
156,157c233,235 |
| 2238 |
< warnings.warn('resource_tracker: process died unexpectedly, ' |
| 2239 |
< 'relaunching. Some resources might leak.') |
| 2240 |
--- |
| 2241 |
> msg = None # message was sent in probe |
| 2242 |
> else: |
| 2243 |
> self._launch() |
| 2244 |
159c237 |
| 2245 |
< fds_to_pass = [] |
| 2246 |
--- |
| 2247 |
> while True: |
| 2248 |
161,193c239,244 |
| 2249 |
< fds_to_pass.append(sys.stderr.fileno()) |
| 2250 |
< except Exception: |
| 2251 |
< pass |
| 2252 |
< cmd = 'from multiprocessing.resource_tracker import main;main(%d)' |
| 2253 |
< r, w = os.pipe() |
| 2254 |
< try: |
| 2255 |
< fds_to_pass.append(r) |
| 2256 |
< # process will out live us, so no need to wait on pid |
| 2257 |
< exe = spawn.get_executable() |
| 2258 |
< args = [exe] + util._args_from_interpreter_flags() |
| 2259 |
< args += ['-c', cmd % r] |
| 2260 |
< # bpo-33613: Register a signal mask that will block the signals. |
| 2261 |
< # This signal mask will be inherited by the child that is going |
| 2262 |
< # to be spawned and will protect the child from a race condition |
| 2263 |
< # that can make the child die before it registers signal handlers |
| 2264 |
< # for SIGINT and SIGTERM. The mask is unregistered after spawning |
| 2265 |
< # the child. |
| 2266 |
< prev_sigmask = None |
| 2267 |
< try: |
| 2268 |
< if _HAVE_SIGMASK: |
| 2269 |
< prev_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) |
| 2270 |
< pid = util.spawnv_passfds(exe, args, fds_to_pass) |
| 2271 |
< finally: |
| 2272 |
< if prev_sigmask is not None: |
| 2273 |
< signal.pthread_sigmask(signal.SIG_SETMASK, prev_sigmask) |
| 2274 |
< except: |
| 2275 |
< os.close(w) |
| 2276 |
< raise |
| 2277 |
< else: |
| 2278 |
< self._fd = w |
| 2279 |
< self._pid = pid |
| 2280 |
< finally: |
| 2281 |
< os.close(r) |
| 2282 |
--- |
| 2283 |
> reentrant_msg = self._reentrant_messages.popleft() |
| 2284 |
> except IndexError: |
| 2285 |
> break |
| 2286 |
> self._write(reentrant_msg) |
| 2287 |
> if msg is not None: |
| 2288 |
> self._write(msg) |
| 2289 |
200c251 |
| 2290 |
< os.write(self._fd, b'PROBE:0:noop\n') |
| 2291 |
--- |
| 2292 |
> os.write(self._fd, self._make_probe_message()) |
| 2293 |
214,230c265 |
| 2294 |
< def _send(self, cmd, name, rtype): |
| 2295 |
< try: |
| 2296 |
< self.ensure_running() |
| 2297 |
< except ReentrantCallError: |
| 2298 |
< # The code below might or might not work, depending on whether |
| 2299 |
< # the resource tracker was already running and still alive. |
| 2300 |
< # Better warn the user. |
| 2301 |
< # (XXX is warnings.warn itself reentrant-safe? :-) |
| 2302 |
< warnings.warn( |
| 2303 |
< f"ResourceTracker called reentrantly for resource cleanup, " |
| 2304 |
< f"which is unsupported. " |
| 2305 |
< f"The {rtype} object {name!r} might leak.") |
| 2306 |
< msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii') |
| 2307 |
< if len(msg) > 512: |
| 2308 |
< # posix guarantees that writes to a pipe of less than PIPE_BUF |
| 2309 |
< # bytes are atomic, and that PIPE_BUF >= 512 |
| 2310 |
< raise ValueError('msg too long') |
| 2311 |
--- |
| 2312 |
> def _write(self, msg): |
| 2313 |
232,233c267 |
| 2314 |
< assert nbytes == len(msg), "nbytes {0:n} but len(msg) {1:n}".format( |
| 2315 |
< nbytes, len(msg)) |
| 2316 |
--- |
| 2317 |
> assert nbytes == len(msg), f"{nbytes=} != {len(msg)=}" |
| 2318 |
234a269,290 |
| 2319 |
> def _send(self, cmd, name, rtype): |
| 2320 |
> # POSIX guarantees that writes to a pipe of less than PIPE_BUF (512 on Linux) |
| 2321 |
> # bytes are atomic. Therefore, we want the message to be shorter than 512 bytes. |
| 2322 |
> # POSIX shm_open() and sem_open() require the name, including its leading slash, |
| 2323 |
> # to be at most NAME_MAX bytes (255 on Linux) |
| 2324 |
> # With json.dump(..., ensure_ascii=True) every non-ASCII byte becomes a 6-char |
| 2325 |
> # escape like \uDC80. |
| 2326 |
> # As we want the overall message to be kept atomic and therefore smaller than 512, |
| 2327 |
> # we encode encode the raw name bytes with URL-safe Base64 - so a 255 long name |
| 2328 |
> # will not exceed 340 bytes. |
| 2329 |
> b = name.encode('utf-8', 'surrogateescape') |
| 2330 |
> if len(b) > 255: |
| 2331 |
> raise ValueError('shared memory name too long (max 255 bytes)') |
| 2332 |
> b64 = base64.urlsafe_b64encode(b).decode('ascii') |
| 2333 |
> |
| 2334 |
> payload = {"cmd": cmd, "rtype": rtype, "base64_name": b64} |
| 2335 |
> msg = (json.dumps(payload, ensure_ascii=True, separators=(",", ":")) + "\n").encode("ascii") |
| 2336 |
> |
| 2337 |
> # The entire JSON message is guaranteed < PIPE_BUF (512 bytes) by construction. |
| 2338 |
> assert len(msg) <= 512, f"internal error: message too long ({len(msg)} bytes)" |
| 2339 |
> |
| 2340 |
> self._ensure_running_and_write(msg) |
| 2341 |
265c321,337 |
| 2342 |
< cmd, name, rtype = line.strip().decode('ascii').split(':') |
| 2343 |
--- |
| 2344 |
> try: |
| 2345 |
> obj = json.loads(line.decode('ascii')) |
| 2346 |
> except Exception as e: |
| 2347 |
> raise ValueError("malformed resource_tracker message: %r" % (line,)) from e |
| 2348 |
> |
| 2349 |
> cmd = obj["cmd"] |
| 2350 |
> rtype = obj["rtype"] |
| 2351 |
> b64 = obj.get("base64_name", "") |
| 2352 |
> |
| 2353 |
> if not isinstance(cmd, str) or not isinstance(rtype, str) or not isinstance(b64, str): |
| 2354 |
> raise ValueError("malformed resource_tracker fields: %r" % (obj,)) |
| 2355 |
> |
| 2356 |
> try: |
| 2357 |
> name = base64.urlsafe_b64decode(b64).decode('utf-8', 'surrogateescape') |
| 2358 |
> except ValueError as e: |
| 2359 |
> raise ValueError("malformed resource_tracker base64_name: %r" % (b64,)) from e |
| 2360 |
> |
| 2361 |
diff Python-3.14.0rc1/Lib/multiprocessing/synchronize.py Python-3.14.1/Lib/multiprocessing/synchronize.py |
| 2362 |
137a138,142 |
| 2363 |
> '''Returns current value of Semaphore. |
| 2364 |
> |
| 2365 |
> Raises NotImplementedError on Mac OSX |
| 2366 |
> because of broken sem_getvalue(). |
| 2367 |
> ''' |
| 2368 |
142c147 |
| 2369 |
< value = self._semlock._get_value() |
| 2370 |
--- |
| 2371 |
> value = self.get_value() |
| 2372 |
158c163 |
| 2373 |
< value = self._semlock._get_value() |
| 2374 |
--- |
| 2375 |
> value = self.get_value() |
| 2376 |
250,251c255,256 |
| 2377 |
< num_waiters = (self._sleeping_count._semlock._get_value() - |
| 2378 |
< self._woken_count._semlock._get_value()) |
| 2379 |
--- |
| 2380 |
> num_waiters = (self._sleeping_count.get_value() - |
| 2381 |
> self._woken_count.get_value()) |
| 2382 |
diff Python-3.14.0rc1/Lib/multiprocessing/util.py Python-3.14.1/Lib/multiprocessing/util.py |
| 2383 |
129,134c129,136 |
| 2384 |
< # Maximum length of a socket file path is usually between 92 and 108 [1], |
| 2385 |
< # but Linux is known to use a size of 108 [2]. BSD-based systems usually |
| 2386 |
< # use a size of 104 or 108 and Windows does not create AF_UNIX sockets. |
| 2387 |
< # |
| 2388 |
< # [1]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_un.h.html |
| 2389 |
< # [2]: https://man7.org/linux/man-pages/man7/unix.7.html. |
| 2390 |
--- |
| 2391 |
> # Maximum length of a NULL-terminated [1] socket file path is usually |
| 2392 |
> # between 92 and 108 [2], but Linux is known to use a size of 108 [3]. |
| 2393 |
> # BSD-based systems usually use a size of 104 or 108 and Windows does |
| 2394 |
> # not create AF_UNIX sockets. |
| 2395 |
> # |
| 2396 |
> # [1]: https://github.com/python/cpython/issues/140734 |
| 2397 |
> # [2]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_un.h.html |
| 2398 |
> # [3]: https://man7.org/linux/man-pages/man7/unix.7.html |
| 2399 |
174c176 |
| 2400 |
< # Thus, the length of socket filename will be: |
| 2401 |
--- |
| 2402 |
> # Thus, the socket file path length (without NULL terminator) will be: |
| 2403 |
178c180,182 |
| 2404 |
< if sun_path_len <= _SUN_PATH_MAX: |
| 2405 |
--- |
| 2406 |
> # Strict inequality to account for the NULL terminator. |
| 2407 |
> # See https://github.com/python/cpython/issues/140734. |
| 2408 |
> if sun_path_len < _SUN_PATH_MAX: |
| 2409 |
204c208 |
| 2410 |
< assert len(base_system_tempdir) + 14 + 14 <= _SUN_PATH_MAX |
| 2411 |
--- |
| 2412 |
> assert len(base_system_tempdir) + 14 + 14 < _SUN_PATH_MAX |
| 2413 |
diff Python-3.14.0rc1/Lib/multiprocessing/dummy/__init__.py Python-3.14.1/Lib/multiprocessing/dummy/__init__.py |
| 2414 |
36c36 |
| 2415 |
< def __init__(self, group=None, target=None, name=None, args=(), kwargs={}): |
| 2416 |
--- |
| 2417 |
> def __init__(self, group=None, target=None, name=None, args=(), kwargs=None): |
| 2418 |
diff Python-3.14.0rc1/Lib/test/_test_multiprocessing.py Python-3.14.1/Lib/test/_test_multiprocessing.py |
| 2419 |
1183c1183 |
| 2420 |
< #queue.put(1) |
| 2421 |
--- |
| 2422 |
> queue.put(1) |
| 2423 |
1207c1207,1209 |
| 2424 |
< time.sleep(DELTA) |
| 2425 |
--- |
| 2426 |
> for _ in support.sleeping_retry(support.SHORT_TIMEOUT): |
| 2427 |
> if not queue_empty(queue): |
| 2428 |
> break |
| 2429 |
1210,1211c1212 |
| 2430 |
< # Hangs unexpectedly, remove for now |
| 2431 |
< #self.assertEqual(queue.get(), 1) |
| 2432 |
--- |
| 2433 |
> self.assertEqual(queue.get_nowait(), 1) |
| 2434 |
1215c1216 |
| 2435 |
< self.assertEqual(queue.get_nowait(), 5) |
| 2436 |
--- |
| 2437 |
> self.assertEqual(queue.get(), 5) |
| 2438 |
5175a5177,5193 |
| 2439 |
> # |
| 2440 |
> # Regression tests for BaseProcess kwargs handling |
| 2441 |
> # |
| 2442 |
> |
| 2443 |
> class TestBaseProcessKwargs(unittest.TestCase): |
| 2444 |
> def test_default_kwargs_not_shared_between_instances(self): |
| 2445 |
> # Creating multiple Process instances without passing kwargs |
| 2446 |
> # must create independent empty dicts (no shared state). |
| 2447 |
> p1 = multiprocessing.Process(target=lambda: None) |
| 2448 |
> p2 = multiprocessing.Process(target=lambda: None) |
| 2449 |
> self.assertIsInstance(p1._kwargs, dict) |
| 2450 |
> self.assertIsInstance(p2._kwargs, dict) |
| 2451 |
> self.assertIsNot(p1._kwargs, p2._kwargs) |
| 2452 |
> # Mutating one should not affect the other |
| 2453 |
> p1._kwargs['x'] = 1 |
| 2454 |
> self.assertNotIn('x', p2._kwargs) |
| 2455 |
> |
| 2456 |
6798,6811d6815 |
| 2457 |
< # Create a test module in the temporary directory on the child's path |
| 2458 |
< # TODO: This can all be simplified once gh-126631 is fixed and we can |
| 2459 |
< # use __main__ instead of a module. |
| 2460 |
< dirname = os.path.join(self._temp_dir, 'preloaded_module') |
| 2461 |
< init_name = os.path.join(dirname, '__init__.py') |
| 2462 |
< os.mkdir(dirname) |
| 2463 |
< with open(init_name, "w") as f: |
| 2464 |
< cmd = '''if 1: |
| 2465 |
< import sys |
| 2466 |
< print('stderr', end='', file=sys.stderr) |
| 2467 |
< print('stdout', end='', file=sys.stdout) |
| 2468 |
< ''' |
| 2469 |
< f.write(cmd) |
| 2470 |
< |
| 2471 |
6813,6814c6817 |
| 2472 |
< env = {'PYTHONPATH': self._temp_dir} |
| 2473 |
< _, out, err = test.support.script_helper.assert_python_ok(name, **env) |
| 2474 |
--- |
| 2475 |
> _, out, err = test.support.script_helper.assert_python_ok(name) |
| 2476 |
6818,6819c6821,6822 |
| 2477 |
< self.assertEqual(err.decode().rstrip(), 'stderr') |
| 2478 |
< self.assertEqual(out.decode().rstrip(), 'stdout') |
| 2479 |
--- |
| 2480 |
> self.assertEqual(err.decode().rstrip(), '__main____mp_main__') |
| 2481 |
> self.assertEqual(out.decode().rstrip(), '__main____mp_main__') |
| 2482 |
6885a6889,6900 |
| 2483 |
> def test_preload_main(self): |
| 2484 |
> # gh-126631: Check that __main__ can be pre-loaded |
| 2485 |
> if multiprocessing.get_start_method() != "forkserver": |
| 2486 |
> self.skipTest("forkserver specific test") |
| 2487 |
> |
| 2488 |
> name = os.path.join(os.path.dirname(__file__), 'mp_preload_main.py') |
| 2489 |
> _, out, err = test.support.script_helper.assert_python_ok(name) |
| 2490 |
> self.assertEqual(err, b'') |
| 2491 |
> |
| 2492 |
> # The trailing empty string comes from split() on output ending with \n |
| 2493 |
> out = out.decode().split("\n") |
| 2494 |
> self.assertEqual(out, ['__main__', '__mp_main__', 'f', 'f', '']) |
| 2495 |
7132a7148,7191 |
| 2496 |
> |
| 2497 |
> |
| 2498 |
> @unittest.skipUnless(HAS_SHMEM, "requires multiprocessing.shared_memory") |
| 2499 |
> class TestSharedMemoryNames(unittest.TestCase): |
| 2500 |
> def test_that_shared_memory_name_with_colons_has_no_resource_tracker_errors(self): |
| 2501 |
> # Test script that creates and cleans up shared memory with colon in name |
| 2502 |
> test_script = textwrap.dedent(""" |
| 2503 |
> import sys |
| 2504 |
> from multiprocessing import shared_memory |
| 2505 |
> import time |
| 2506 |
> |
| 2507 |
> # Test various patterns of colons in names |
| 2508 |
> test_names = [ |
| 2509 |
> "a:b", |
| 2510 |
> "a:b:c", |
| 2511 |
> "test:name:with:many:colons", |
| 2512 |
> ":starts:with:colon", |
| 2513 |
> "ends:with:colon:", |
| 2514 |
> "::double::colons::", |
| 2515 |
> "name\\nwithnewline", |
| 2516 |
> "name-with-trailing-newline\\n", |
| 2517 |
> "\\nname-starts-with-newline", |
| 2518 |
> "colons:and\\nnewlines:mix", |
| 2519 |
> "multi\\nline\\nname", |
| 2520 |
> ] |
| 2521 |
> |
| 2522 |
> for name in test_names: |
| 2523 |
> try: |
| 2524 |
> shm = shared_memory.SharedMemory(create=True, size=100, name=name) |
| 2525 |
> shm.buf[:5] = b'hello' # Write something to the shared memory |
| 2526 |
> shm.close() |
| 2527 |
> shm.unlink() |
| 2528 |
> |
| 2529 |
> except Exception as e: |
| 2530 |
> print(f"Error with name '{name}': {e}", file=sys.stderr) |
| 2531 |
> sys.exit(1) |
| 2532 |
> |
| 2533 |
> print("SUCCESS") |
| 2534 |
> """) |
| 2535 |
> |
| 2536 |
> rc, out, err = script_helper.assert_python_ok("-c", test_script) |
| 2537 |
> self.assertIn(b"SUCCESS", out) |
| 2538 |
> self.assertNotIn(b"traceback", err.lower(), err) |
| 2539 |
> self.assertNotIn(b"resource_tracker.py", err, err) |
| 2540 |
diff Python-3.14.0rc1/Lib/test/mp_preload_flush.py Python-3.14.1/Lib/test/mp_preload_flush.py |
| 2541 |
4c4,5 |
| 2542 |
< modname = 'preloaded_module' |
| 2543 |
--- |
| 2544 |
> print(__name__, end='', file=sys.stderr) |
| 2545 |
> print(__name__, end='', file=sys.stdout) |
| 2546 |
6,7d6 |
| 2547 |
< if modname in sys.modules: |
| 2548 |
< raise AssertionError(f'{modname!r} is not in sys.modules') |
| 2549 |
9d7 |
| 2550 |
< multiprocessing.set_forkserver_preload([modname]) |
| 2551 |
14,15d11 |
| 2552 |
< elif modname not in sys.modules: |
| 2553 |
< raise AssertionError(f'{modname!r} is not in sys.modules') |
| 2554 |
# ---------------------------------------------------------------------- |
| 2555 |
diff Python-3.14.1/Lib/multiprocessing/resource_tracker.py Python-3.14.2/Lib/multiprocessing/resource_tracker.py |
| 2556 |
70a71,77 |
| 2557 |
> # True to use colon-separated lines, rather than JSON lines, |
| 2558 |
> # for internal communication. (Mainly for testing). |
| 2559 |
> # Filenames not supported by the simple format will always be sent |
| 2560 |
> # using JSON. |
| 2561 |
> # The reader should understand all formats. |
| 2562 |
> self._use_simple_format = True |
| 2563 |
> |
| 2564 |
203c210,212 |
| 2565 |
< """Return a JSON-encoded probe message.""" |
| 2566 |
--- |
| 2567 |
> """Return a probe message.""" |
| 2568 |
> if self._use_simple_format: |
| 2569 |
> return b'PROBE:0:noop\n' |
| 2570 |
269a279,287 |
| 2571 |
> if self._use_simple_format and '\n' not in name: |
| 2572 |
> msg = f"{cmd}:{name}:{rtype}\n".encode("ascii") |
| 2573 |
> if len(msg) > 512: |
| 2574 |
> # posix guarantees that writes to a pipe of less than PIPE_BUF |
| 2575 |
> # bytes are atomic, and that PIPE_BUF >= 512 |
| 2576 |
> raise ValueError('msg too long') |
| 2577 |
> self._ensure_running_and_write(msg) |
| 2578 |
> return |
| 2579 |
> |
| 2580 |
288a307 |
| 2581 |
> assert msg.startswith(b'{') |
| 2582 |
298a318,341 |
| 2583 |
> def _decode_message(line): |
| 2584 |
> if line.startswith(b'{'): |
| 2585 |
> try: |
| 2586 |
> obj = json.loads(line.decode('ascii')) |
| 2587 |
> except Exception as e: |
| 2588 |
> raise ValueError("malformed resource_tracker message: %r" % (line,)) from e |
| 2589 |
> |
| 2590 |
> cmd = obj["cmd"] |
| 2591 |
> rtype = obj["rtype"] |
| 2592 |
> b64 = obj.get("base64_name", "") |
| 2593 |
> |
| 2594 |
> if not isinstance(cmd, str) or not isinstance(rtype, str) or not isinstance(b64, str): |
| 2595 |
> raise ValueError("malformed resource_tracker fields: %r" % (obj,)) |
| 2596 |
> |
| 2597 |
> try: |
| 2598 |
> name = base64.urlsafe_b64decode(b64).decode('utf-8', 'surrogateescape') |
| 2599 |
> except ValueError as e: |
| 2600 |
> raise ValueError("malformed resource_tracker base64_name: %r" % (b64,)) from e |
| 2601 |
> else: |
| 2602 |
> cmd, rest = line.strip().decode('ascii').split(':', maxsplit=1) |
| 2603 |
> name, rtype = rest.rsplit(':', maxsplit=1) |
| 2604 |
> return cmd, rtype, name |
| 2605 |
> |
| 2606 |
> |
| 2607 |
321,337c364 |
| 2608 |
< try: |
| 2609 |
< obj = json.loads(line.decode('ascii')) |
| 2610 |
< except Exception as e: |
| 2611 |
< raise ValueError("malformed resource_tracker message: %r" % (line,)) from e |
| 2612 |
< |
| 2613 |
< cmd = obj["cmd"] |
| 2614 |
< rtype = obj["rtype"] |
| 2615 |
< b64 = obj.get("base64_name", "") |
| 2616 |
< |
| 2617 |
< if not isinstance(cmd, str) or not isinstance(rtype, str) or not isinstance(b64, str): |
| 2618 |
< raise ValueError("malformed resource_tracker fields: %r" % (obj,)) |
| 2619 |
< |
| 2620 |
< try: |
| 2621 |
< name = base64.urlsafe_b64decode(b64).decode('utf-8', 'surrogateescape') |
| 2622 |
< except ValueError as e: |
| 2623 |
< raise ValueError("malformed resource_tracker base64_name: %r" % (b64,)) from e |
| 2624 |
< |
| 2625 |
--- |
| 2626 |
> cmd, rtype, name = _decode_message(line) |
| 2627 |
diff Python-3.14.1/Lib/test/_test_multiprocessing.py Python-3.14.2/Lib/test/_test_multiprocessing.py |
| 2628 |
42c42 |
| 2629 |
< |
| 2630 |
--- |
| 2631 |
> from test.support import subTests |
| 2632 |
4286a4287,4299 |
| 2633 |
> def resource_tracker_format_subtests(func): |
| 2634 |
> """Run given test using both resource tracker communication formats""" |
| 2635 |
> def _inner(self, *args, **kwargs): |
| 2636 |
> tracker = resource_tracker._resource_tracker |
| 2637 |
> for use_simple_format in False, True: |
| 2638 |
> with ( |
| 2639 |
> self.subTest(use_simple_format=use_simple_format), |
| 2640 |
> unittest.mock.patch.object( |
| 2641 |
> tracker, '_use_simple_format', use_simple_format) |
| 2642 |
> ): |
| 2643 |
> func(self, *args, **kwargs) |
| 2644 |
> return _inner |
| 2645 |
> |
| 2646 |
4563a4577 |
| 2647 |
> @resource_tracker_format_subtests |
| 2648 |
4813a4828 |
| 2649 |
> @resource_tracker_format_subtests |
| 2650 |
4840a4856 |
| 2651 |
> @resource_tracker_format_subtests |
| 2652 |
7152c7168,7170 |
| 2653 |
< def test_that_shared_memory_name_with_colons_has_no_resource_tracker_errors(self): |
| 2654 |
--- |
| 2655 |
> @subTests('use_simple_format', (True, False)) |
| 2656 |
> def test_that_shared_memory_name_with_colons_has_no_resource_tracker_errors( |
| 2657 |
> self, use_simple_format): |
| 2658 |
7156a7175 |
| 2659 |
> from multiprocessing import resource_tracker |
| 2660 |
7158a7178,7179 |
| 2661 |
> resource_tracker._resource_tracker._use_simple_format = %s |
| 2662 |
> |
| 2663 |
7186c7207 |
| 2664 |
< """) |
| 2665 |
--- |
| 2666 |
> """ % use_simple_format) |