| 1 |
cp -rf py3.14/examples . |
| 2 |
cp -rf py3.14/doc . |
| 3 |
cp -f py3.14/index.html . |
| 4 |
cp -rf py3.14/_multiprocess _multiprocess |
| 5 |
cp -rf Python-3.15.0a1/Modules/_multiprocessing Modules/_multiprocess |
| 6 |
cp -rf py3.14/multiprocess multiprocess |
| 7 |
# ---------------------------------------------------------------------- |
| 8 |
$ diff Python-3.15.0a1/Modules/_multiprocessing/semaphore.c Modules/_multiprocess/semaphore.c |
| 9 |
10,11c10 |
| 10 |
< #include "multiprocessing.h" |
| 11 |
< #include "pycore_object.h" // _PyObject_VisitType() |
| 12 |
--- |
| 13 |
> #include "multiprocess.h" |
| 14 |
19c18 |
| 15 |
< // These match the values in Lib/multiprocessing/synchronize.py |
| 16 |
--- |
| 17 |
> // These match the values in multiprocess/synchronize.py |
| 18 |
43,44c42,43 |
| 19 |
< module _multiprocessing |
| 20 |
< class _multiprocessing.SemLock "SemLockObject *" "&_PyMp_SemLockType" |
| 21 |
--- |
| 22 |
> module _multiprocess |
| 23 |
> class _multiprocess.SemLock "SemLockObject *" "&_PyMp_SemLockType" |
| 24 |
89c88 |
| 25 |
< _multiprocessing.SemLock.acquire |
| 26 |
--- |
| 27 |
> _multiprocess.SemLock.acquire |
| 28 |
98,99c97,98 |
| 29 |
< _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 30 |
< PyObject *timeout_obj) |
| 31 |
--- |
| 32 |
> _multiprocess_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 33 |
> PyObject *timeout_obj) |
| 34 |
181c180 |
| 35 |
< _multiprocessing.SemLock.release |
| 36 |
--- |
| 37 |
> _multiprocess.SemLock.release |
| 38 |
187c186 |
| 39 |
< _multiprocessing_SemLock_release_impl(SemLockObject *self) |
| 40 |
--- |
| 41 |
> _multiprocess_SemLock_release_impl(SemLockObject *self) |
| 42 |
307c306 |
| 43 |
< _multiprocessing.SemLock.acquire |
| 44 |
--- |
| 45 |
> _multiprocess.SemLock.acquire |
| 46 |
316,317c315,316 |
| 47 |
< _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 48 |
< PyObject *timeout_obj) |
| 49 |
--- |
| 50 |
> _multiprocess_SemLock_acquire_impl(SemLockObject *self, int blocking, |
| 51 |
> PyObject *timeout_obj) |
| 52 |
393c392 |
| 53 |
< _multiprocessing.SemLock.release |
| 54 |
--- |
| 55 |
> _multiprocess.SemLock.release |
| 56 |
399c398 |
| 57 |
< _multiprocessing_SemLock_release_impl(SemLockObject *self) |
| 58 |
--- |
| 59 |
> _multiprocess_SemLock_release_impl(SemLockObject *self) |
| 60 |
483c482 |
| 61 |
< _multiprocessing.SemLock.__new__ |
| 62 |
--- |
| 63 |
> _multiprocess.SemLock.__new__ |
| 64 |
494,495c493,494 |
| 65 |
< _multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value, |
| 66 |
< int maxvalue, const char *name, int unlink) |
| 67 |
--- |
| 68 |
> _multiprocess_SemLock_impl(PyTypeObject *type, int kind, int value, |
| 69 |
> int maxvalue, const char *name, int unlink) |
| 70 |
542c541 |
| 71 |
< _multiprocessing.SemLock._rebuild |
| 72 |
--- |
| 73 |
> _multiprocess.SemLock._rebuild |
| 74 |
553,555c552,554 |
| 75 |
< _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle, |
| 76 |
< int kind, int maxvalue, |
| 77 |
< const char *name) |
| 78 |
--- |
| 79 |
> _multiprocess_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle, |
| 80 |
> int kind, int maxvalue, |
| 81 |
> const char *name) |
| 82 |
596c595 |
| 83 |
< _multiprocessing.SemLock._count |
| 84 |
--- |
| 85 |
> _multiprocess.SemLock._count |
| 86 |
602c601 |
| 87 |
< _multiprocessing_SemLock__count_impl(SemLockObject *self) |
| 88 |
--- |
| 89 |
> _multiprocess_SemLock__count_impl(SemLockObject *self) |
| 90 |
609c608 |
| 91 |
< _multiprocessing.SemLock._is_mine |
| 92 |
--- |
| 93 |
> _multiprocess.SemLock._is_mine |
| 94 |
615c614 |
| 95 |
< _multiprocessing_SemLock__is_mine_impl(SemLockObject *self) |
| 96 |
--- |
| 97 |
> _multiprocess_SemLock__is_mine_impl(SemLockObject *self) |
| 98 |
623c622 |
| 99 |
< _multiprocessing.SemLock._get_value |
| 100 |
--- |
| 101 |
> _multiprocess.SemLock._get_value |
| 102 |
629c628 |
| 103 |
< _multiprocessing_SemLock__get_value_impl(SemLockObject *self) |
| 104 |
--- |
| 105 |
> _multiprocess_SemLock__get_value_impl(SemLockObject *self) |
| 106 |
648c647 |
| 107 |
< _multiprocessing.SemLock._is_zero |
| 108 |
--- |
| 109 |
> _multiprocess.SemLock._is_zero |
| 110 |
654c653 |
| 111 |
< _multiprocessing_SemLock__is_zero_impl(SemLockObject *self) |
| 112 |
--- |
| 113 |
> _multiprocess_SemLock__is_zero_impl(SemLockObject *self) |
| 114 |
676c675 |
| 115 |
< _multiprocessing.SemLock._after_fork |
| 116 |
--- |
| 117 |
> _multiprocess.SemLock._after_fork |
| 118 |
682c681 |
| 119 |
< _multiprocessing_SemLock__after_fork_impl(SemLockObject *self) |
| 120 |
--- |
| 121 |
> _multiprocess_SemLock__after_fork_impl(SemLockObject *self) |
| 122 |
691c690 |
| 123 |
< _multiprocessing.SemLock.__enter__ |
| 124 |
--- |
| 125 |
> _multiprocess.SemLock.__enter__ |
| 126 |
697c696 |
| 127 |
< _multiprocessing_SemLock___enter___impl(SemLockObject *self) |
| 128 |
--- |
| 129 |
> _multiprocess_SemLock___enter___impl(SemLockObject *self) |
| 130 |
700c699 |
| 131 |
< return _multiprocessing_SemLock_acquire_impl(self, 1, Py_None); |
| 132 |
--- |
| 133 |
> return _multiprocess_SemLock_acquire_impl(self, 1, Py_None); |
| 134 |
705c704 |
| 135 |
< _multiprocessing.SemLock.__exit__ |
| 136 |
--- |
| 137 |
> _multiprocess.SemLock.__exit__ |
| 138 |
716,718c715,717 |
| 139 |
< _multiprocessing_SemLock___exit___impl(SemLockObject *self, |
| 140 |
< PyObject *exc_type, |
| 141 |
< PyObject *exc_value, PyObject *exc_tb) |
| 142 |
--- |
| 143 |
> _multiprocess_SemLock___exit___impl(SemLockObject *self, |
| 144 |
> PyObject *exc_type, |
| 145 |
> PyObject *exc_value, PyObject *exc_tb) |
| 146 |
721c720,727 |
| 147 |
< return _multiprocessing_SemLock_release_impl(self); |
| 148 |
--- |
| 149 |
> return _multiprocess_SemLock_release_impl(self); |
| 150 |
> } |
| 151 |
> |
| 152 |
> static int |
| 153 |
> semlock_traverse(PyObject *s, visitproc visit, void *arg) |
| 154 |
> { |
| 155 |
> Py_VISIT(Py_TYPE(s)); |
| 156 |
> return 0; |
| 157 |
729,738c735,744 |
| 158 |
< _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF |
| 159 |
< _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF |
| 160 |
< _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF |
| 161 |
< _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF |
| 162 |
< _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF |
| 163 |
< _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF |
| 164 |
< _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF |
| 165 |
< _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF |
| 166 |
< _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF |
| 167 |
< _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF |
| 168 |
--- |
| 169 |
> _MULTIPROCESS_SEMLOCK_ACQUIRE_METHODDEF |
| 170 |
> _MULTIPROCESS_SEMLOCK_RELEASE_METHODDEF |
| 171 |
> _MULTIPROCESS_SEMLOCK___ENTER___METHODDEF |
| 172 |
> _MULTIPROCESS_SEMLOCK___EXIT___METHODDEF |
| 173 |
> _MULTIPROCESS_SEMLOCK__COUNT_METHODDEF |
| 174 |
> _MULTIPROCESS_SEMLOCK__IS_MINE_METHODDEF |
| 175 |
> _MULTIPROCESS_SEMLOCK__GET_VALUE_METHODDEF |
| 176 |
> _MULTIPROCESS_SEMLOCK__IS_ZERO_METHODDEF |
| 177 |
> _MULTIPROCESS_SEMLOCK__REBUILD_METHODDEF |
| 178 |
> _MULTIPROCESS_SEMLOCK__AFTER_FORK_METHODDEF |
| 179 |
769,770c775,776 |
| 180 |
< {Py_tp_new, _multiprocessing_SemLock}, |
| 181 |
< {Py_tp_traverse, _PyObject_VisitType}, |
| 182 |
--- |
| 183 |
> {Py_tp_new, _multiprocess_SemLock}, |
| 184 |
> {Py_tp_traverse, semlock_traverse}, |
| 185 |
777c783 |
| 186 |
< .name = "_multiprocessing.SemLock", |
| 187 |
--- |
| 188 |
> .name = "_multiprocess.SemLock", |
| 189 |
$ diff Python-3.15.0a1/Modules/_multiprocessing/multiprocessing.h Modules/_multiprocess/multiprocess.h |
| 190 |
1,2c1,2 |
| 191 |
< #ifndef MULTIPROCESSING_H |
| 192 |
< #define MULTIPROCESSING_H |
| 193 |
--- |
| 194 |
> #ifndef MULTIPROCESS_H |
| 195 |
> #define MULTIPROCESS_H |
| 196 |
104c104 |
| 197 |
< #endif /* MULTIPROCESSING_H */ |
| 198 |
--- |
| 199 |
> #endif /* MULTIPROCESS_H */ |
| 200 |
$ diff Python-3.15.0a1/Modules/_multiprocessing/multiprocessing.c Modules/_multiprocess/multiprocess.c |
| 201 |
2c2 |
| 202 |
< * Extension module used by multiprocessing package |
| 203 |
--- |
| 204 |
> * Extension module used by multiprocess package |
| 205 |
4c4 |
| 206 |
< * multiprocessing.c |
| 207 |
--- |
| 208 |
> * multiprocess.c |
| 209 |
10c10 |
| 210 |
< #include "multiprocessing.h" |
| 211 |
--- |
| 212 |
> #include "multiprocess.h" |
| 213 |
30c30 |
| 214 |
< module _multiprocessing |
| 215 |
--- |
| 216 |
> module _multiprocess |
| 217 |
77c77 |
| 218 |
< _multiprocessing.closesocket |
| 219 |
--- |
| 220 |
> _multiprocess.closesocket |
| 221 |
85c85 |
| 222 |
< _multiprocessing_closesocket_impl(PyObject *module, HANDLE handle) |
| 223 |
--- |
| 224 |
> _multiprocess_closesocket_impl(PyObject *module, HANDLE handle) |
| 225 |
100c100 |
| 226 |
< _multiprocessing.recv |
| 227 |
--- |
| 228 |
> _multiprocess.recv |
| 229 |
109c109 |
| 230 |
< _multiprocessing_recv_impl(PyObject *module, HANDLE handle, int size) |
| 231 |
--- |
| 232 |
> _multiprocess_recv_impl(PyObject *module, HANDLE handle, int size) |
| 233 |
112,113c112,116 |
| 234 |
< PyBytesWriter *writer = PyBytesWriter_Create(size); |
| 235 |
< if (!writer) { |
| 236 |
--- |
| 237 |
> int nread; |
| 238 |
> PyObject *buf; |
| 239 |
> |
| 240 |
> buf = PyBytes_FromStringAndSize(NULL, size); |
| 241 |
> if (!buf) |
| 242 |
115,116d117 |
| 243 |
< } |
| 244 |
< char *buf = PyBytesWriter_GetData(writer); |
| 245 |
118d118 |
| 246 |
< Py_ssize_t nread; |
| 247 |
120c120 |
| 248 |
< nread = recv((SOCKET) handle, buf, size, 0); |
| 249 |
--- |
| 250 |
> nread = recv((SOCKET) handle, PyBytes_AS_STRING(buf), size, 0); |
| 251 |
124c124 |
| 252 |
< PyBytesWriter_Discard(writer); |
| 253 |
--- |
| 254 |
> Py_DECREF(buf); |
| 255 |
127c127,128 |
| 256 |
< return PyBytesWriter_FinishWithSize(writer, nread); |
| 257 |
--- |
| 258 |
> _PyBytes_Resize(&buf, nread); |
| 259 |
> return buf; |
| 260 |
131c132 |
| 261 |
< _multiprocessing.send |
| 262 |
--- |
| 263 |
> _multiprocess.send |
| 264 |
140c141 |
| 265 |
< _multiprocessing_send_impl(PyObject *module, HANDLE handle, Py_buffer *buf) |
| 266 |
--- |
| 267 |
> _multiprocess_send_impl(PyObject *module, HANDLE handle, Py_buffer *buf) |
| 268 |
159c160 |
| 269 |
< _multiprocessing.sem_unlink |
| 270 |
--- |
| 271 |
> _multiprocess.sem_unlink |
| 272 |
167c168 |
| 273 |
< _multiprocessing_sem_unlink_impl(PyObject *module, const char *name) |
| 274 |
--- |
| 275 |
> _multiprocess_sem_unlink_impl(PyObject *module, const char *name) |
| 276 |
179,181c180,182 |
| 277 |
< _MULTIPROCESSING_CLOSESOCKET_METHODDEF |
| 278 |
< _MULTIPROCESSING_RECV_METHODDEF |
| 279 |
< _MULTIPROCESSING_SEND_METHODDEF |
| 280 |
--- |
| 281 |
> _MULTIPROCESS_CLOSESOCKET_METHODDEF |
| 282 |
> _MULTIPROCESS_RECV_METHODDEF |
| 283 |
> _MULTIPROCESS_SEND_METHODDEF |
| 284 |
184c185 |
| 285 |
< _MULTIPROCESSING_SEM_UNLINK_METHODDEF |
| 286 |
--- |
| 287 |
> _MULTIPROCESS_SEM_UNLINK_METHODDEF |
| 288 |
195c196 |
| 289 |
< multiprocessing_exec(PyObject *module) |
| 290 |
--- |
| 291 |
> multiprocess_exec(PyObject *module) |
| 292 |
276,277c277,278 |
| 293 |
< static PyModuleDef_Slot multiprocessing_slots[] = { |
| 294 |
< {Py_mod_exec, multiprocessing_exec}, |
| 295 |
--- |
| 296 |
> static PyModuleDef_Slot multiprocess_slots[] = { |
| 297 |
> {Py_mod_exec, multiprocess_exec}, |
| 298 |
283c284 |
| 299 |
< static struct PyModuleDef multiprocessing_module = { |
| 300 |
--- |
| 301 |
> static struct PyModuleDef multiprocess_module = { |
| 302 |
285c286 |
| 303 |
< .m_name = "_multiprocessing", |
| 304 |
--- |
| 305 |
> .m_name = "_multiprocess", |
| 306 |
288c289 |
| 307 |
< .m_slots = multiprocessing_slots, |
| 308 |
--- |
| 309 |
> .m_slots = multiprocess_slots, |
| 310 |
292c293 |
| 311 |
< PyInit__multiprocessing(void) |
| 312 |
--- |
| 313 |
> PyInit__multiprocess(void) |
| 314 |
294c295 |
| 315 |
< return PyModuleDef_Init(&multiprocessing_module); |
| 316 |
--- |
| 317 |
> return PyModuleDef_Init(&multiprocess_module); |
| 318 |
# ---------------------------------------------------------------------- |
| 319 |
diff Python-3.14.0rc1/Lib/multiprocessing/forkserver.py Python-3.15.0a1/Lib/multiprocessing/forkserver.py |
| 320 |
147a148 |
| 321 |
> main_kws = {} |
| 322 |
149d149 |
| 323 |
< desired_keys = {'main_path', 'sys_path'} |
| 324 |
151,153c151,154 |
| 325 |
< main_kws = {x: y for x, y in data.items() if x in desired_keys} |
| 326 |
< else: |
| 327 |
< main_kws = {} |
| 328 |
--- |
| 329 |
> if 'sys_path' in data: |
| 330 |
> main_kws['sys_path'] = data['sys_path'] |
| 331 |
> if 'init_main_from_path' in data: |
| 332 |
> main_kws['main_path'] = data['init_main_from_path'] |
| 333 |
diff Python-3.14.0rc1/Lib/multiprocessing/popen_spawn_posix.py Python-3.15.0a1/Lib/multiprocessing/popen_spawn_posix.py |
| 334 |
59a60,63 |
| 335 |
> os.close(child_r) |
| 336 |
> child_r = None |
| 337 |
> os.close(child_w) |
| 338 |
> child_w = None |
| 339 |
diff Python-3.14.0rc1/Lib/multiprocessing/process.py Python-3.15.0a1/Lib/multiprocessing/process.py |
| 340 |
80c80 |
| 341 |
< def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, |
| 342 |
--- |
| 343 |
> def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, |
| 344 |
92c92 |
| 345 |
< self._kwargs = dict(kwargs) |
| 346 |
--- |
| 347 |
> self._kwargs = dict(kwargs) if kwargs else {} |
| 348 |
diff Python-3.14.0rc1/Lib/multiprocessing/resource_tracker.py Python-3.15.0a1/Lib/multiprocessing/resource_tracker.py |
| 349 |
22a23 |
| 350 |
> from collections import deque |
| 351 |
64a66 |
| 352 |
> self._reentrant_messages = deque() |
| 353 |
101c103 |
| 354 |
< return self._reentrant_call_error() |
| 355 |
--- |
| 356 |
> raise self._reentrant_call_error() |
| 357 |
130a133,194 |
| 358 |
> return self._ensure_running_and_write() |
| 359 |
> |
| 360 |
> def _teardown_dead_process(self): |
| 361 |
> os.close(self._fd) |
| 362 |
> |
| 363 |
> # Clean-up to avoid dangling processes. |
| 364 |
> try: |
| 365 |
> # _pid can be None if this process is a child from another |
| 366 |
> # python process, which has started the resource_tracker. |
| 367 |
> if self._pid is not None: |
| 368 |
> os.waitpid(self._pid, 0) |
| 369 |
> except ChildProcessError: |
| 370 |
> # The resource_tracker has already been terminated. |
| 371 |
> pass |
| 372 |
> self._fd = None |
| 373 |
> self._pid = None |
| 374 |
> self._exitcode = None |
| 375 |
> |
| 376 |
> warnings.warn('resource_tracker: process died unexpectedly, ' |
| 377 |
> 'relaunching. Some resources might leak.') |
| 378 |
> |
| 379 |
> def _launch(self): |
| 380 |
> fds_to_pass = [] |
| 381 |
> try: |
| 382 |
> fds_to_pass.append(sys.stderr.fileno()) |
| 383 |
> except Exception: |
| 384 |
> pass |
| 385 |
> r, w = os.pipe() |
| 386 |
> try: |
| 387 |
> fds_to_pass.append(r) |
| 388 |
> # process will out live us, so no need to wait on pid |
| 389 |
> exe = spawn.get_executable() |
| 390 |
> args = [ |
| 391 |
> exe, |
| 392 |
> *util._args_from_interpreter_flags(), |
| 393 |
> '-c', |
| 394 |
> f'from multiprocessing.resource_tracker import main;main({r})', |
| 395 |
> ] |
| 396 |
> # bpo-33613: Register a signal mask that will block the signals. |
| 397 |
> # This signal mask will be inherited by the child that is going |
| 398 |
> # to be spawned and will protect the child from a race condition |
| 399 |
> # that can make the child die before it registers signal handlers |
| 400 |
> # for SIGINT and SIGTERM. The mask is unregistered after spawning |
| 401 |
> # the child. |
| 402 |
> prev_sigmask = None |
| 403 |
> try: |
| 404 |
> if _HAVE_SIGMASK: |
| 405 |
> prev_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) |
| 406 |
> pid = util.spawnv_passfds(exe, args, fds_to_pass) |
| 407 |
> finally: |
| 408 |
> if prev_sigmask is not None: |
| 409 |
> signal.pthread_sigmask(signal.SIG_SETMASK, prev_sigmask) |
| 410 |
> except: |
| 411 |
> os.close(w) |
| 412 |
> raise |
| 413 |
> else: |
| 414 |
> self._fd = w |
| 415 |
> self._pid = pid |
| 416 |
> finally: |
| 417 |
> os.close(r) |
| 418 |
> |
| 419 |
> def _ensure_running_and_write(self, msg=None): |
| 420 |
134c198,201 |
| 421 |
< return self._reentrant_call_error() |
| 422 |
--- |
| 423 |
> if msg is None: |
| 424 |
> raise self._reentrant_call_error() |
| 425 |
> return self._reentrant_messages.append(msg) |
| 426 |
> |
| 427 |
137,143c204,207 |
| 428 |
< if self._check_alive(): |
| 429 |
< # => still alive |
| 430 |
< return |
| 431 |
< # => dead, launch it again |
| 432 |
< os.close(self._fd) |
| 433 |
< |
| 434 |
< # Clean-up to avoid dangling processes. |
| 435 |
--- |
| 436 |
> if msg is None: |
| 437 |
> to_send = b'PROBE:0:noop\n' |
| 438 |
> else: |
| 439 |
> to_send = msg |
| 440 |
145,154c209,212 |
| 441 |
< # _pid can be None if this process is a child from another |
| 442 |
< # python process, which has started the resource_tracker. |
| 443 |
< if self._pid is not None: |
| 444 |
< os.waitpid(self._pid, 0) |
| 445 |
< except ChildProcessError: |
| 446 |
< # The resource_tracker has already been terminated. |
| 447 |
< pass |
| 448 |
< self._fd = None |
| 449 |
< self._pid = None |
| 450 |
< self._exitcode = None |
| 451 |
--- |
| 452 |
> self._write(to_send) |
| 453 |
> except OSError: |
| 454 |
> self._teardown_dead_process() |
| 455 |
> self._launch() |
| 456 |
156,157c214,216 |
| 457 |
< warnings.warn('resource_tracker: process died unexpectedly, ' |
| 458 |
< 'relaunching. Some resources might leak.') |
| 459 |
--- |
| 460 |
> msg = None # message was sent in probe |
| 461 |
> else: |
| 462 |
> self._launch() |
| 463 |
159c218 |
| 464 |
< fds_to_pass = [] |
| 465 |
--- |
| 466 |
> while True: |
| 467 |
161,193c220,225 |
| 468 |
< fds_to_pass.append(sys.stderr.fileno()) |
| 469 |
< except Exception: |
| 470 |
< pass |
| 471 |
< cmd = 'from multiprocessing.resource_tracker import main;main(%d)' |
| 472 |
< r, w = os.pipe() |
| 473 |
< try: |
| 474 |
< fds_to_pass.append(r) |
| 475 |
< # process will out live us, so no need to wait on pid |
| 476 |
< exe = spawn.get_executable() |
| 477 |
< args = [exe] + util._args_from_interpreter_flags() |
| 478 |
< args += ['-c', cmd % r] |
| 479 |
< # bpo-33613: Register a signal mask that will block the signals. |
| 480 |
< # This signal mask will be inherited by the child that is going |
| 481 |
< # to be spawned and will protect the child from a race condition |
| 482 |
< # that can make the child die before it registers signal handlers |
| 483 |
< # for SIGINT and SIGTERM. The mask is unregistered after spawning |
| 484 |
< # the child. |
| 485 |
< prev_sigmask = None |
| 486 |
< try: |
| 487 |
< if _HAVE_SIGMASK: |
| 488 |
< prev_sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS) |
| 489 |
< pid = util.spawnv_passfds(exe, args, fds_to_pass) |
| 490 |
< finally: |
| 491 |
< if prev_sigmask is not None: |
| 492 |
< signal.pthread_sigmask(signal.SIG_SETMASK, prev_sigmask) |
| 493 |
< except: |
| 494 |
< os.close(w) |
| 495 |
< raise |
| 496 |
< else: |
| 497 |
< self._fd = w |
| 498 |
< self._pid = pid |
| 499 |
< finally: |
| 500 |
< os.close(r) |
| 501 |
--- |
| 502 |
> reentrant_msg = self._reentrant_messages.popleft() |
| 503 |
> except IndexError: |
| 504 |
> break |
| 505 |
> self._write(reentrant_msg) |
| 506 |
> if msg is not None: |
| 507 |
> self._write(msg) |
| 508 |
213a246,249 |
| 509 |
> def _write(self, msg): |
| 510 |
> nbytes = os.write(self._fd, msg) |
| 511 |
> assert nbytes == len(msg), f"{nbytes=} != {len(msg)=}" |
| 512 |
> |
| 513 |
215,226c251 |
| 514 |
< try: |
| 515 |
< self.ensure_running() |
| 516 |
< except ReentrantCallError: |
| 517 |
< # The code below might or might not work, depending on whether |
| 518 |
< # the resource tracker was already running and still alive. |
| 519 |
< # Better warn the user. |
| 520 |
< # (XXX is warnings.warn itself reentrant-safe? :-) |
| 521 |
< warnings.warn( |
| 522 |
< f"ResourceTracker called reentrantly for resource cleanup, " |
| 523 |
< f"which is unsupported. " |
| 524 |
< f"The {rtype} object {name!r} might leak.") |
| 525 |
< msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii') |
| 526 |
--- |
| 527 |
> msg = f"{cmd}:{name}:{rtype}\n".encode("ascii") |
| 528 |
231,233d255 |
| 529 |
< nbytes = os.write(self._fd, msg) |
| 530 |
< assert nbytes == len(msg), "nbytes {0:n} but len(msg) {1:n}".format( |
| 531 |
< nbytes, len(msg)) |
| 532 |
234a257 |
| 533 |
> self._ensure_running_and_write(msg) |
| 534 |
diff Python-3.14.0rc1/Lib/multiprocessing/sharedctypes.py Python-3.15.0a1/Lib/multiprocessing/sharedctypes.py |
| 535 |
40c40,45 |
| 536 |
< size = ctypes.sizeof(type_) |
| 537 |
--- |
| 538 |
> try: |
| 539 |
> size = ctypes.sizeof(type_) |
| 540 |
> except TypeError as e: |
| 541 |
> raise TypeError("bad typecode (must be a ctypes type or one of " |
| 542 |
> "c, b, B, u, h, H, i, I, l, L, q, Q, f or d)") from e |
| 543 |
> |
| 544 |
diff Python-3.14.0rc1/Lib/test/_test_multiprocessing.py Python-3.15.0a1/Lib/test/_test_multiprocessing.py |
| 545 |
42c42 |
| 546 |
< |
| 547 |
--- |
| 548 |
> from test.support.script_helper import assert_python_failure, assert_python_ok |
| 549 |
327a328 |
| 550 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 551 |
343a345 |
| 552 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 553 |
390a393 |
| 554 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 555 |
410a414 |
| 556 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 557 |
448a453 |
| 558 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 559 |
488a494 |
| 560 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 561 |
528a535 |
| 562 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 563 |
585a593 |
| 564 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 565 |
593a602 |
| 566 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 567 |
598a608 |
| 568 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 569 |
602a613 |
| 570 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 571 |
617a629 |
| 572 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 573 |
645a658 |
| 574 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 575 |
669a683 |
| 576 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 577 |
691a706 |
| 578 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 579 |
723a739 |
| 580 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 581 |
759a776 |
| 582 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 583 |
821a839 |
| 584 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 585 |
845a864 |
| 586 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 587 |
864a884 |
| 588 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 589 |
1014a1035 |
| 590 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 591 |
1023a1045 |
| 592 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 593 |
1053a1076 |
| 594 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 595 |
1120a1144 |
| 596 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 597 |
1189a1214 |
| 598 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 599 |
1250a1276 |
| 600 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 601 |
1300a1327 |
| 602 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 603 |
1343a1371 |
| 604 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 605 |
1466a1495 |
| 606 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 607 |
1529a1559 |
| 608 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 609 |
1555a1586 |
| 610 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 611 |
1614a1646 |
| 612 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 613 |
1725a1758 |
| 614 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 615 |
1767a1801 |
| 616 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 617 |
1836a1871 |
| 618 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 619 |
1909a1945 |
| 620 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 621 |
1944a1981 |
| 622 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 623 |
1976a2014 |
| 624 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 625 |
2004a2043 |
| 626 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 627 |
2200a2240 |
| 628 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 629 |
2207a2248 |
| 630 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 631 |
2218a2260 |
| 632 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 633 |
2234a2277 |
| 634 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 635 |
2256a2300 |
| 636 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 637 |
2286a2331 |
| 638 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 639 |
2321a2367 |
| 640 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 641 |
2347a2394 |
| 642 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 643 |
2366a2414 |
| 644 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 645 |
2387a2436 |
| 646 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 647 |
2429c2478 |
| 648 |
< |
| 649 |
--- |
| 650 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 651 |
2476a2526,2531 |
| 652 |
> @unittest.skipIf(c_int is None, "requires _ctypes") |
| 653 |
> def test_invalid_typecode(self): |
| 654 |
> with self.assertRaisesRegex(TypeError, 'bad typecode'): |
| 655 |
> self.Value('x', None) |
| 656 |
> with self.assertRaisesRegex(TypeError, 'bad typecode'): |
| 657 |
> self.RawValue('x', None) |
| 658 |
2486a2542 |
| 659 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 660 |
2556a2613,2618 |
| 661 |
> @unittest.skipIf(c_int is None, "requires _ctypes") |
| 662 |
> def test_invalid_typecode(self): |
| 663 |
> with self.assertRaisesRegex(TypeError, 'bad typecode'): |
| 664 |
> self.Array('x', []) |
| 665 |
> with self.assertRaisesRegex(TypeError, 'bad typecode'): |
| 666 |
> self.RawArray('x', []) |
| 667 |
2792,2793c2854,2856 |
| 668 |
< super().setUpClass() |
| 669 |
< cls.pool = cls.Pool(4) |
| 670 |
--- |
| 671 |
> with warnings_helper.ignore_fork_in_thread_deprecation_warnings(): |
| 672 |
> super().setUpClass() |
| 673 |
> cls.pool = cls.Pool(4) |
| 674 |
2891a2955 |
| 675 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 676 |
2988a3053 |
| 677 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 678 |
3003a3069 |
| 679 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 680 |
3020a3087 |
| 681 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 682 |
3032a3100 |
| 683 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 684 |
3046a3115 |
| 685 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 686 |
3085a3155 |
| 687 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 688 |
3088a3159 |
| 689 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 690 |
3095a3167 |
| 691 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 692 |
3130a3203 |
| 693 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 694 |
3146a3220 |
| 695 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 696 |
3171a3246 |
| 697 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 698 |
3186a3262 |
| 699 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 700 |
3211a3288 |
| 701 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 702 |
3240a3318 |
| 703 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 704 |
3313a3392 |
| 705 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 706 |
3324a3404 |
| 707 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 708 |
3333a3414 |
| 709 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 710 |
3403a3485 |
| 711 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 712 |
3444a3527 |
| 713 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 714 |
3497c3580,3581 |
| 715 |
< self.mgr = multiprocessing.Manager() |
| 716 |
--- |
| 717 |
> with warnings_helper.ignore_fork_in_thread_deprecation_warnings(): |
| 718 |
> self.mgr = multiprocessing.Manager() |
| 719 |
3502a3587 |
| 720 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 721 |
3513a3599 |
| 722 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 723 |
3539a3626 |
| 724 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 725 |
3631a3719 |
| 726 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 727 |
3707a3796 |
| 728 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 729 |
3726a3816 |
| 730 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 731 |
3763a3854 |
| 732 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 733 |
3862a3954 |
| 734 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 735 |
3873a3966 |
| 736 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 737 |
3918a4012 |
| 738 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 739 |
3941a4036 |
| 740 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 741 |
3959a4055 |
| 742 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 743 |
4027a4124 |
| 744 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 745 |
4085a4183 |
| 746 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 747 |
4248a4347 |
| 748 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 749 |
4509a4609 |
| 750 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 751 |
4537a4638 |
| 752 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 753 |
4582a4684 |
| 754 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 755 |
4921a5024 |
| 756 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 757 |
5048a5152 |
| 758 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 759 |
5132a5237 |
| 760 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 761 |
5175a5281,5297 |
| 762 |
> # |
| 763 |
> # Regression tests for BaseProcess kwargs handling |
| 764 |
> # |
| 765 |
> |
| 766 |
> class TestBaseProcessKwargs(unittest.TestCase): |
| 767 |
> def test_default_kwargs_not_shared_between_instances(self): |
| 768 |
> # Creating multiple Process instances without passing kwargs |
| 769 |
> # must create independent empty dicts (no shared state). |
| 770 |
> p1 = multiprocessing.Process(target=lambda: None) |
| 771 |
> p2 = multiprocessing.Process(target=lambda: None) |
| 772 |
> self.assertIsInstance(p1._kwargs, dict) |
| 773 |
> self.assertIsInstance(p2._kwargs, dict) |
| 774 |
> self.assertIsNot(p1._kwargs, p2._kwargs) |
| 775 |
> # Mutating one should not affect the other |
| 776 |
> p1._kwargs['x'] = 1 |
| 777 |
> self.assertNotIn('x', p2._kwargs) |
| 778 |
> |
| 779 |
5255,5257c5377,5380 |
| 780 |
< self.mgr = multiprocessing.Manager() |
| 781 |
< self.ns = self.mgr.Namespace() |
| 782 |
< self.ns.test = 0 |
| 783 |
--- |
| 784 |
> with warnings_helper.ignore_fork_in_thread_deprecation_warnings(): |
| 785 |
> self.mgr = multiprocessing.Manager() |
| 786 |
> self.ns = self.mgr.Namespace() |
| 787 |
> self.ns.test = 0 |
| 788 |
5262a5386 |
| 789 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 790 |
5270a5395 |
| 791 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 792 |
5327a5453 |
| 793 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 794 |
5332a5459 |
| 795 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 796 |
5337a5465 |
| 797 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 798 |
5356a5485 |
| 799 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 800 |
5396a5526 |
| 801 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 802 |
5460a5591 |
| 803 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 804 |
5504a5636 |
| 805 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 806 |
5581a5714 |
| 807 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 808 |
5638a5772 |
| 809 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 810 |
5689a5824 |
| 811 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 812 |
5734a5870 |
| 813 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 814 |
5767a5904 |
| 815 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 816 |
5801a5939 |
| 817 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 818 |
5821a5960 |
| 819 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 820 |
5878a6018 |
| 821 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 822 |
5911a6052 |
| 823 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 824 |
6066a6208 |
| 825 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 826 |
6167a6310 |
| 827 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 828 |
6275c6418,6419 |
| 829 |
< self.manager.start() |
| 830 |
--- |
| 831 |
> with warnings_helper.ignore_fork_in_thread_deprecation_warnings(): |
| 832 |
> self.manager.start() |
| 833 |
6323a6468 |
| 834 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 835 |
6335a6481 |
| 836 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 837 |
6347a6494 |
| 838 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 839 |
6355a6503 |
| 840 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 841 |
6368a6517 |
| 842 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 843 |
6377a6527 |
| 844 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 845 |
6387a6538 |
| 846 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 847 |
6401a6553 |
| 848 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 849 |
6409a6562 |
| 850 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 851 |
6443a6597 |
| 852 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 853 |
6484a6639 |
| 854 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 855 |
6498a6654 |
| 856 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 857 |
6512a6669 |
| 858 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 859 |
6522a6680 |
| 860 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 861 |
6641a6800 |
| 862 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 863 |
6658a6818 |
| 864 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 865 |
6711a6872 |
| 866 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 867 |
6863a7025 |
| 868 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 869 |
6885a7048,7059 |
| 870 |
> def test_preload_main(self): |
| 871 |
> # gh-126631: Check that __main__ can be pre-loaded |
| 872 |
> if multiprocessing.get_start_method() != "forkserver": |
| 873 |
> self.skipTest("forkserver specific test") |
| 874 |
> |
| 875 |
> name = os.path.join(os.path.dirname(__file__), 'mp_preload_main.py') |
| 876 |
> _, out, err = test.support.script_helper.assert_python_ok(name) |
| 877 |
> self.assertEqual(err, b'') |
| 878 |
> |
| 879 |
> # The trailing empty string comes from split() on output ending with \n |
| 880 |
> out = out.decode().split("\n") |
| 881 |
> self.assertEqual(out, ['__main__', '__mp_main__', 'f', 'f', '']) |
| 882 |
6965,6966c7139,7141 |
| 883 |
< super().setUpClass() |
| 884 |
< cls.manager = multiprocessing.Manager() |
| 885 |
--- |
| 886 |
> with warnings_helper.ignore_fork_in_thread_deprecation_warnings(): |
| 887 |
> super().setUpClass() |
| 888 |
> cls.manager = multiprocessing.Manager() |
| 889 |
7132a7308,7366 |
| 890 |
> |
| 891 |
> |
| 892 |
> @unittest.skipIf(sys.platform != "linux", "Linux only") |
| 893 |
> class ForkInThreads(unittest.TestCase): |
| 894 |
> |
| 895 |
> def test_fork(self): |
| 896 |
> code = """ |
| 897 |
> import os, sys, threading, time |
| 898 |
> |
| 899 |
> t = threading.Thread(target=time.sleep, args=(1,), daemon=True) |
| 900 |
> t.start() |
| 901 |
> |
| 902 |
> assert threading.active_count() == 2 |
| 903 |
> |
| 904 |
> pid = os.fork() |
| 905 |
> if pid < 0: |
| 906 |
> print("Fork failed") |
| 907 |
> elif pid == 0: |
| 908 |
> print("In child") |
| 909 |
> sys.exit(0) |
| 910 |
> print("In parent") |
| 911 |
> """ |
| 912 |
> |
| 913 |
> res = assert_python_ok("-c", code, PYTHONWARNINGS='always') |
| 914 |
> self.assertIn(b'In child', res.out) |
| 915 |
> self.assertIn(b'In parent', res.out) |
| 916 |
> self.assertIn(b'DeprecationWarning', res.err) |
| 917 |
> self.assertIn(b'is multi-threaded, use of fork() may lead to deadlocks in the child', res.err) |
| 918 |
> |
| 919 |
> res = assert_python_failure("-c", code, PYTHONWARNINGS='error') |
| 920 |
> self.assertIn(b'DeprecationWarning', res.err) |
| 921 |
> self.assertIn(b'is multi-threaded, use of fork() may lead to deadlocks in the child', res.err) |
| 922 |
> |
| 923 |
> def test_forkpty(self): |
| 924 |
> code = """ |
| 925 |
> import os, sys, threading, time |
| 926 |
> |
| 927 |
> t = threading.Thread(target=time.sleep, args=(1,), daemon=True) |
| 928 |
> t.start() |
| 929 |
> |
| 930 |
> assert threading.active_count() == 2 |
| 931 |
> |
| 932 |
> pid, _ = os.forkpty() |
| 933 |
> if pid < 0: |
| 934 |
> print(f"forkpty failed") |
| 935 |
> elif pid == 0: |
| 936 |
> print(f"In child") |
| 937 |
> sys.exit(0) |
| 938 |
> print(f"In parent") |
| 939 |
> """ |
| 940 |
> |
| 941 |
> res = assert_python_ok("-c", code, PYTHONWARNINGS='always') |
| 942 |
> self.assertIn(b'In parent', res.out) |
| 943 |
> self.assertIn(b'DeprecationWarning', res.err) |
| 944 |
> self.assertIn(b'is multi-threaded, use of forkpty() may lead to deadlocks in the child', res.err) |
| 945 |
> |
| 946 |
> res = assert_python_failure("-c", code, PYTHONWARNINGS='error') |
| 947 |
> self.assertIn(b'DeprecationWarning', res.err) |
| 948 |
> self.assertIn(b'is multi-threaded, use of forkpty() may lead to deadlocks in the child', res.err) |
| 949 |
# ---------------------------------------------------------------------- |
| 950 |
diff Python-3.15.0a1/Lib/multiprocessing/heap.py Python-3.15.0a2/Lib/multiprocessing/heap.py |
| 951 |
327,330d326 |
| 952 |
< if size < 0: |
| 953 |
< raise ValueError("Size {0:n} out of range".format(size)) |
| 954 |
< if sys.maxsize <= size: |
| 955 |
< raise OverflowError("Size {0:n} too large".format(size)) |
| 956 |
diff Python-3.15.0a1/Lib/multiprocessing/resource_tracker.py Python-3.15.0a2/Lib/multiprocessing/resource_tracker.py |
| 957 |
17a18 |
| 958 |
> import base64 |
| 959 |
24a26,27 |
| 960 |
> import json |
| 961 |
> |
| 962 |
114c117,122 |
| 963 |
< _, status = waitpid(self._pid, 0) |
| 964 |
--- |
| 965 |
> try: |
| 966 |
> _, status = waitpid(self._pid, 0) |
| 967 |
> except ChildProcessError: |
| 968 |
> self._pid = None |
| 969 |
> self._exitcode = None |
| 970 |
> return |
| 971 |
193a202,212 |
| 972 |
> def _make_probe_message(self): |
| 973 |
> """Return a JSON-encoded probe message.""" |
| 974 |
> return ( |
| 975 |
> json.dumps( |
| 976 |
> {"cmd": "PROBE", "rtype": "noop"}, |
| 977 |
> ensure_ascii=True, |
| 978 |
> separators=(",", ":"), |
| 979 |
> ) |
| 980 |
> + "\n" |
| 981 |
> ).encode("ascii") |
| 982 |
> |
| 983 |
205c224 |
| 984 |
< to_send = b'PROBE:0:noop\n' |
| 985 |
--- |
| 986 |
> to_send = self._make_probe_message() |
| 987 |
232c251 |
| 988 |
< os.write(self._fd, b'PROBE:0:noop\n') |
| 989 |
--- |
| 990 |
> os.write(self._fd, self._make_probe_message()) |
| 991 |
251,255c270,288 |
| 992 |
< msg = f"{cmd}:{name}:{rtype}\n".encode("ascii") |
| 993 |
< if len(msg) > 512: |
| 994 |
< # posix guarantees that writes to a pipe of less than PIPE_BUF |
| 995 |
< # bytes are atomic, and that PIPE_BUF >= 512 |
| 996 |
< raise ValueError('msg too long') |
| 997 |
--- |
| 998 |
> # POSIX guarantees that writes to a pipe of less than PIPE_BUF (512 on Linux) |
| 999 |
> # bytes are atomic. Therefore, we want the message to be shorter than 512 bytes. |
| 1000 |
> # POSIX shm_open() and sem_open() require the name, including its leading slash, |
| 1001 |
> # to be at most NAME_MAX bytes (255 on Linux) |
| 1002 |
> # With json.dump(..., ensure_ascii=True) every non-ASCII byte becomes a 6-char |
| 1003 |
> # escape like \uDC80. |
| 1004 |
> # As we want the overall message to be kept atomic and therefore smaller than 512, |
| 1005 |
> # we encode encode the raw name bytes with URL-safe Base64 - so a 255 long name |
| 1006 |
> # will not exceed 340 bytes. |
| 1007 |
> b = name.encode('utf-8', 'surrogateescape') |
| 1008 |
> if len(b) > 255: |
| 1009 |
> raise ValueError('shared memory name too long (max 255 bytes)') |
| 1010 |
> b64 = base64.urlsafe_b64encode(b).decode('ascii') |
| 1011 |
> |
| 1012 |
> payload = {"cmd": cmd, "rtype": rtype, "base64_name": b64} |
| 1013 |
> msg = (json.dumps(payload, ensure_ascii=True, separators=(",", ":")) + "\n").encode("ascii") |
| 1014 |
> |
| 1015 |
> # The entire JSON message is guaranteed < PIPE_BUF (512 bytes) by construction. |
| 1016 |
> assert len(msg) <= 512, f"internal error: message too long ({len(msg)} bytes)" |
| 1017 |
288c321,337 |
| 1018 |
< cmd, name, rtype = line.strip().decode('ascii').split(':') |
| 1019 |
--- |
| 1020 |
> try: |
| 1021 |
> obj = json.loads(line.decode('ascii')) |
| 1022 |
> except Exception as e: |
| 1023 |
> raise ValueError("malformed resource_tracker message: %r" % (line,)) from e |
| 1024 |
> |
| 1025 |
> cmd = obj["cmd"] |
| 1026 |
> rtype = obj["rtype"] |
| 1027 |
> b64 = obj.get("base64_name", "") |
| 1028 |
> |
| 1029 |
> if not isinstance(cmd, str) or not isinstance(rtype, str) or not isinstance(b64, str): |
| 1030 |
> raise ValueError("malformed resource_tracker fields: %r" % (obj,)) |
| 1031 |
> |
| 1032 |
> try: |
| 1033 |
> name = base64.urlsafe_b64decode(b64).decode('utf-8', 'surrogateescape') |
| 1034 |
> except ValueError as e: |
| 1035 |
> raise ValueError("malformed resource_tracker base64_name: %r" % (b64,)) from e |
| 1036 |
> |
| 1037 |
diff Python-3.15.0a1/Lib/multiprocessing/util.py Python-3.15.0a2/Lib/multiprocessing/util.py |
| 1038 |
129,134c129,136 |
| 1039 |
< # Maximum length of a socket file path is usually between 92 and 108 [1], |
| 1040 |
< # but Linux is known to use a size of 108 [2]. BSD-based systems usually |
| 1041 |
< # use a size of 104 or 108 and Windows does not create AF_UNIX sockets. |
| 1042 |
< # |
| 1043 |
< # [1]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_un.h.html |
| 1044 |
< # [2]: https://man7.org/linux/man-pages/man7/unix.7.html. |
| 1045 |
--- |
| 1046 |
> # Maximum length of a NULL-terminated [1] socket file path is usually |
| 1047 |
> # between 92 and 108 [2], but Linux is known to use a size of 108 [3]. |
| 1048 |
> # BSD-based systems usually use a size of 104 or 108 and Windows does |
| 1049 |
> # not create AF_UNIX sockets. |
| 1050 |
> # |
| 1051 |
> # [1]: https://github.com/python/cpython/issues/140734 |
| 1052 |
> # [2]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_un.h.html |
| 1053 |
> # [3]: https://man7.org/linux/man-pages/man7/unix.7.html |
| 1054 |
174c176 |
| 1055 |
< # Thus, the length of socket filename will be: |
| 1056 |
--- |
| 1057 |
> # Thus, the socket file path length (without NULL terminator) will be: |
| 1058 |
178c180,182 |
| 1059 |
< if sun_path_len <= _SUN_PATH_MAX: |
| 1060 |
--- |
| 1061 |
> # Strict inequality to account for the NULL terminator. |
| 1062 |
> # See https://github.com/python/cpython/issues/140734. |
| 1063 |
> if sun_path_len < _SUN_PATH_MAX: |
| 1064 |
204c208 |
| 1065 |
< assert len(base_system_tempdir) + 14 + 14 <= _SUN_PATH_MAX |
| 1066 |
--- |
| 1067 |
> assert len(base_system_tempdir) + 14 + 14 < _SUN_PATH_MAX |
| 1068 |
diff Python-3.15.0a1/Lib/test/_test_multiprocessing.py Python-3.15.0a2/Lib/test/_test_multiprocessing.py |
| 1069 |
7366a7367,7409 |
| 1070 |
> |
| 1071 |
> @unittest.skipUnless(HAS_SHMEM, "requires multiprocessing.shared_memory") |
| 1072 |
> class TestSharedMemoryNames(unittest.TestCase): |
| 1073 |
> def test_that_shared_memory_name_with_colons_has_no_resource_tracker_errors(self): |
| 1074 |
> # Test script that creates and cleans up shared memory with colon in name |
| 1075 |
> test_script = textwrap.dedent(""" |
| 1076 |
> import sys |
| 1077 |
> from multiprocessing import shared_memory |
| 1078 |
> import time |
| 1079 |
> |
| 1080 |
> # Test various patterns of colons in names |
| 1081 |
> test_names = [ |
| 1082 |
> "a:b", |
| 1083 |
> "a:b:c", |
| 1084 |
> "test:name:with:many:colons", |
| 1085 |
> ":starts:with:colon", |
| 1086 |
> "ends:with:colon:", |
| 1087 |
> "::double::colons::", |
| 1088 |
> "name\\nwithnewline", |
| 1089 |
> "name-with-trailing-newline\\n", |
| 1090 |
> "\\nname-starts-with-newline", |
| 1091 |
> "colons:and\\nnewlines:mix", |
| 1092 |
> "multi\\nline\\nname", |
| 1093 |
> ] |
| 1094 |
> |
| 1095 |
> for name in test_names: |
| 1096 |
> try: |
| 1097 |
> shm = shared_memory.SharedMemory(create=True, size=100, name=name) |
| 1098 |
> shm.buf[:5] = b'hello' # Write something to the shared memory |
| 1099 |
> shm.close() |
| 1100 |
> shm.unlink() |
| 1101 |
> |
| 1102 |
> except Exception as e: |
| 1103 |
> print(f"Error with name '{name}': {e}", file=sys.stderr) |
| 1104 |
> sys.exit(1) |
| 1105 |
> |
| 1106 |
> print("SUCCESS") |
| 1107 |
> """) |
| 1108 |
> |
| 1109 |
> rc, out, err = assert_python_ok("-c", test_script) |
| 1110 |
> self.assertIn(b"SUCCESS", out) |
| 1111 |
> self.assertNotIn(b"traceback", err.lower(), err) |
| 1112 |
> self.assertNotIn(b"resource_tracker.py", err, err) |
| 1113 |
# ---------------------------------------------------------------------- |
| 1114 |
diff Python-3.15.0a2/Lib/multiprocessing/connection.py Python-3.15.0a3/Lib/multiprocessing/connection.py |
| 1115 |
712,713c712 |
| 1116 |
< res = _winapi.WaitForMultipleObjects( |
| 1117 |
< [ov.event], False, INFINITE) |
| 1118 |
--- |
| 1119 |
> _winapi.WaitForMultipleObjects([ov.event], False, INFINITE) |
| 1120 |
diff Python-3.15.0a2/Lib/multiprocessing/queues.py Python-3.15.0a3/Lib/multiprocessing/queues.py |
| 1121 |
124c124 |
| 1122 |
< return self._maxsize - self._sem._semlock._get_value() |
| 1123 |
--- |
| 1124 |
> return self._maxsize - self._sem.get_value() |
| 1125 |
diff Python-3.15.0a2/Lib/multiprocessing/resource_tracker.py Python-3.15.0a3/Lib/multiprocessing/resource_tracker.py |
| 1126 |
70a71,77 |
| 1127 |
> # True to use colon-separated lines, rather than JSON lines, |
| 1128 |
> # for internal communication. (Mainly for testing). |
| 1129 |
> # Filenames not supported by the simple format will always be sent |
| 1130 |
> # using JSON. |
| 1131 |
> # The reader should understand all formats. |
| 1132 |
> self._use_simple_format = False |
| 1133 |
> |
| 1134 |
203c210,212 |
| 1135 |
< """Return a JSON-encoded probe message.""" |
| 1136 |
--- |
| 1137 |
> """Return a probe message.""" |
| 1138 |
> if self._use_simple_format: |
| 1139 |
> return b'PROBE:0:noop\n' |
| 1140 |
269a279,287 |
| 1141 |
> if self._use_simple_format and '\n' not in name: |
| 1142 |
> msg = f"{cmd}:{name}:{rtype}\n".encode("ascii") |
| 1143 |
> if len(msg) > 512: |
| 1144 |
> # posix guarantees that writes to a pipe of less than PIPE_BUF |
| 1145 |
> # bytes are atomic, and that PIPE_BUF >= 512 |
| 1146 |
> raise ValueError('msg too long') |
| 1147 |
> self._ensure_running_and_write(msg) |
| 1148 |
> return |
| 1149 |
> |
| 1150 |
288a307 |
| 1151 |
> assert msg.startswith(b'{') |
| 1152 |
298a318,341 |
| 1153 |
> def _decode_message(line): |
| 1154 |
> if line.startswith(b'{'): |
| 1155 |
> try: |
| 1156 |
> obj = json.loads(line.decode('ascii')) |
| 1157 |
> except Exception as e: |
| 1158 |
> raise ValueError("malformed resource_tracker message: %r" % (line,)) from e |
| 1159 |
> |
| 1160 |
> cmd = obj["cmd"] |
| 1161 |
> rtype = obj["rtype"] |
| 1162 |
> b64 = obj.get("base64_name", "") |
| 1163 |
> |
| 1164 |
> if not isinstance(cmd, str) or not isinstance(rtype, str) or not isinstance(b64, str): |
| 1165 |
> raise ValueError("malformed resource_tracker fields: %r" % (obj,)) |
| 1166 |
> |
| 1167 |
> try: |
| 1168 |
> name = base64.urlsafe_b64decode(b64).decode('utf-8', 'surrogateescape') |
| 1169 |
> except ValueError as e: |
| 1170 |
> raise ValueError("malformed resource_tracker base64_name: %r" % (b64,)) from e |
| 1171 |
> else: |
| 1172 |
> cmd, rest = line.strip().decode('ascii').split(':', maxsplit=1) |
| 1173 |
> name, rtype = rest.rsplit(':', maxsplit=1) |
| 1174 |
> return cmd, rtype, name |
| 1175 |
> |
| 1176 |
> |
| 1177 |
321,337c364 |
| 1178 |
< try: |
| 1179 |
< obj = json.loads(line.decode('ascii')) |
| 1180 |
< except Exception as e: |
| 1181 |
< raise ValueError("malformed resource_tracker message: %r" % (line,)) from e |
| 1182 |
< |
| 1183 |
< cmd = obj["cmd"] |
| 1184 |
< rtype = obj["rtype"] |
| 1185 |
< b64 = obj.get("base64_name", "") |
| 1186 |
< |
| 1187 |
< if not isinstance(cmd, str) or not isinstance(rtype, str) or not isinstance(b64, str): |
| 1188 |
< raise ValueError("malformed resource_tracker fields: %r" % (obj,)) |
| 1189 |
< |
| 1190 |
< try: |
| 1191 |
< name = base64.urlsafe_b64decode(b64).decode('utf-8', 'surrogateescape') |
| 1192 |
< except ValueError as e: |
| 1193 |
< raise ValueError("malformed resource_tracker base64_name: %r" % (b64,)) from e |
| 1194 |
< |
| 1195 |
--- |
| 1196 |
> cmd, rtype, name = _decode_message(line) |
| 1197 |
diff Python-3.15.0a2/Lib/multiprocessing/synchronize.py Python-3.15.0a3/Lib/multiprocessing/synchronize.py |
| 1198 |
137a138,142 |
| 1199 |
> '''Returns current value of Semaphore. |
| 1200 |
> |
| 1201 |
> Raises NotImplementedError on Mac OSX |
| 1202 |
> because of broken sem_getvalue(). |
| 1203 |
> ''' |
| 1204 |
142c147 |
| 1205 |
< value = self._semlock._get_value() |
| 1206 |
--- |
| 1207 |
> value = self.get_value() |
| 1208 |
158c163 |
| 1209 |
< value = self._semlock._get_value() |
| 1210 |
--- |
| 1211 |
> value = self.get_value() |
| 1212 |
250,251c255,256 |
| 1213 |
< num_waiters = (self._sleeping_count._semlock._get_value() - |
| 1214 |
< self._woken_count._semlock._get_value()) |
| 1215 |
--- |
| 1216 |
> num_waiters = (self._sleeping_count.get_value() - |
| 1217 |
> self._woken_count.get_value()) |
| 1218 |
diff Python-3.15.0a2/Lib/test/_test_multiprocessing.py Python-3.15.0a3/Lib/test/_test_multiprocessing.py |
| 1219 |
41a42 |
| 1220 |
> from test.support import subTests |
| 1221 |
1207c1208 |
| 1222 |
< #queue.put(1) |
| 1223 |
--- |
| 1224 |
> queue.put(1) |
| 1225 |
1232c1233,1235 |
| 1226 |
< time.sleep(DELTA) |
| 1227 |
--- |
| 1228 |
> for _ in support.sleeping_retry(support.SHORT_TIMEOUT): |
| 1229 |
> if not queue_empty(queue): |
| 1230 |
> break |
| 1231 |
1235,1236c1238 |
| 1232 |
< # Hangs unexpectedly, remove for now |
| 1233 |
< #self.assertEqual(queue.get(), 1) |
| 1234 |
--- |
| 1235 |
> self.assertEqual(queue.get_nowait(), 1) |
| 1236 |
1240c1242 |
| 1237 |
< self.assertEqual(queue.get_nowait(), 5) |
| 1238 |
--- |
| 1239 |
> self.assertEqual(queue.get(), 5) |
| 1240 |
4384a4387,4399 |
| 1241 |
> def resource_tracker_format_subtests(func): |
| 1242 |
> """Run given test using both resource tracker communication formats""" |
| 1243 |
> def _inner(self, *args, **kwargs): |
| 1244 |
> tracker = resource_tracker._resource_tracker |
| 1245 |
> for use_simple_format in False, True: |
| 1246 |
> with ( |
| 1247 |
> self.subTest(use_simple_format=use_simple_format), |
| 1248 |
> unittest.mock.patch.object( |
| 1249 |
> tracker, '_use_simple_format', use_simple_format) |
| 1250 |
> ): |
| 1251 |
> func(self, *args, **kwargs) |
| 1252 |
> return _inner |
| 1253 |
> |
| 1254 |
4663a4679 |
| 1255 |
> @resource_tracker_format_subtests |
| 1256 |
4914a4931 |
| 1257 |
> @resource_tracker_format_subtests |
| 1258 |
4941a4959 |
| 1259 |
> @resource_tracker_format_subtests |
| 1260 |
6959,6972d6976 |
| 1261 |
< # Create a test module in the temporary directory on the child's path |
| 1262 |
< # TODO: This can all be simplified once gh-126631 is fixed and we can |
| 1263 |
< # use __main__ instead of a module. |
| 1264 |
< dirname = os.path.join(self._temp_dir, 'preloaded_module') |
| 1265 |
< init_name = os.path.join(dirname, '__init__.py') |
| 1266 |
< os.mkdir(dirname) |
| 1267 |
< with open(init_name, "w") as f: |
| 1268 |
< cmd = '''if 1: |
| 1269 |
< import sys |
| 1270 |
< print('stderr', end='', file=sys.stderr) |
| 1271 |
< print('stdout', end='', file=sys.stdout) |
| 1272 |
< ''' |
| 1273 |
< f.write(cmd) |
| 1274 |
< |
| 1275 |
6974,6975c6978 |
| 1276 |
< env = {'PYTHONPATH': self._temp_dir} |
| 1277 |
< _, out, err = test.support.script_helper.assert_python_ok(name, **env) |
| 1278 |
--- |
| 1279 |
> _, out, err = test.support.script_helper.assert_python_ok(name) |
| 1280 |
6979,6980c6982,6983 |
| 1281 |
< self.assertEqual(err.decode().rstrip(), 'stderr') |
| 1282 |
< self.assertEqual(out.decode().rstrip(), 'stdout') |
| 1283 |
--- |
| 1284 |
> self.assertEqual(err.decode().rstrip(), '__main____mp_main__') |
| 1285 |
> self.assertEqual(out.decode().rstrip(), '__main____mp_main__') |
| 1286 |
7370c7373,7375 |
| 1287 |
< def test_that_shared_memory_name_with_colons_has_no_resource_tracker_errors(self): |
| 1288 |
--- |
| 1289 |
> @subTests('use_simple_format', (True, False)) |
| 1290 |
> def test_that_shared_memory_name_with_colons_has_no_resource_tracker_errors( |
| 1291 |
> self, use_simple_format): |
| 1292 |
7374a7380 |
| 1293 |
> from multiprocessing import resource_tracker |
| 1294 |
7376a7383,7384 |
| 1295 |
> resource_tracker._resource_tracker._use_simple_format = %s |
| 1296 |
> |
| 1297 |
7404c7412 |
| 1298 |
< """) |
| 1299 |
--- |
| 1300 |
> """ % use_simple_format) |
| 1301 |
diff Python-3.15.0a2/Lib/test/mp_preload_flush.py Python-3.15.0a3/Lib/test/mp_preload_flush.py |
| 1302 |
4c4,5 |
| 1303 |
< modname = 'preloaded_module' |
| 1304 |
--- |
| 1305 |
> print(__name__, end='', file=sys.stderr) |
| 1306 |
> print(__name__, end='', file=sys.stdout) |
| 1307 |
6,7d6 |
| 1308 |
< if modname in sys.modules: |
| 1309 |
< raise AssertionError(f'{modname!r} is not in sys.modules') |
| 1310 |
9d7 |
| 1311 |
< multiprocessing.set_forkserver_preload([modname]) |
| 1312 |
14,15d11 |
| 1313 |
< elif modname not in sys.modules: |
| 1314 |
< raise AssertionError(f'{modname!r} is not in sys.modules') |
| 1315 |
# ---------------------------------------------------------------------- |
| 1316 |
diff Python-3.15.0a3/Lib/multiprocessing/forkserver.py Python-3.15.0a5/Lib/multiprocessing/forkserver.py |
| 1317 |
154a155,156 |
| 1318 |
> if 'sys_argv' in data: |
| 1319 |
> main_kws['sys_argv'] = data['sys_argv'] |
| 1320 |
200c202 |
| 1321 |
< *, authkey_r=None): |
| 1322 |
--- |
| 1323 |
> *, sys_argv=None, authkey_r=None): |
| 1324 |
211a214,215 |
| 1325 |
> if sys_argv is not None: |
| 1326 |
> sys.argv[:] = sys_argv |
| 1327 |
diff Python-3.15.0a3/Lib/multiprocessing/spawn.py Python-3.15.0a5/Lib/multiprocessing/spawn.py |
| 1328 |
187c187 |
| 1329 |
< start_method=get_start_method(), |
| 1330 |
--- |
| 1331 |
> start_method=get_start_method(allow_none=True), |
| 1332 |
diff Python-3.15.0a3/Lib/test/_test_multiprocessing.py Python-3.15.0a5/Lib/test/_test_multiprocessing.py |
| 1333 |
3394a3395 |
| 1334 |
> @support.skip_if_sanitizer('TSan: leaks threads', thread=True) |
| 1335 |
3406a3408 |
| 1336 |
> @support.skip_if_sanitizer('TSan: leaks threads', thread=True) |
| 1337 |
3416a3419 |
| 1338 |
> @support.skip_if_sanitizer('TSan: leaks threads', thread=True) |
| 1339 |
3487a3491 |
| 1340 |
> @support.skip_if_sanitizer('TSan: leaks threads', thread=True) |
| 1341 |
3529a3534 |
| 1342 |
> @support.skip_if_sanitizer("TSan: leaks threads", thread=True) |
| 1343 |
5969a5975,5994 |
| 1344 |
> @staticmethod |
| 1345 |
> def _dummy_func(): |
| 1346 |
> pass |
| 1347 |
> |
| 1348 |
> @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 1349 |
> def test_spawn_dont_set_context(self): |
| 1350 |
> # Run a process with spawn or forkserver context may change |
| 1351 |
> # the global start method, see gh-109263. |
| 1352 |
> for method in ('fork', 'spawn', 'forkserver'): |
| 1353 |
> multiprocessing.set_start_method(None, force=True) |
| 1354 |
> |
| 1355 |
> try: |
| 1356 |
> ctx = multiprocessing.get_context(method) |
| 1357 |
> except ValueError: |
| 1358 |
> continue |
| 1359 |
> process = ctx.Process(target=self._dummy_func) |
| 1360 |
> process.start() |
| 1361 |
> process.join() |
| 1362 |
> self.assertIsNone(multiprocessing.get_start_method(allow_none=True)) |
| 1363 |
> |
| 1364 |
7063a7089,7108 |
| 1365 |
> def test_preload_main_sys_argv(self): |
| 1366 |
> # gh-143706: Check that sys.argv is set before __main__ is pre-loaded |
| 1367 |
> if multiprocessing.get_start_method() != "forkserver": |
| 1368 |
> self.skipTest("forkserver specific test") |
| 1369 |
> |
| 1370 |
> name = os.path.join(os.path.dirname(__file__), 'mp_preload_sysargv.py') |
| 1371 |
> _, out, err = test.support.script_helper.assert_python_ok( |
| 1372 |
> name, 'foo', 'bar') |
| 1373 |
> self.assertEqual(err, b'') |
| 1374 |
> |
| 1375 |
> out = out.decode().split("\n") |
| 1376 |
> expected_argv = "['foo', 'bar']" |
| 1377 |
> self.assertEqual(out, [ |
| 1378 |
> f"module:{expected_argv}", |
| 1379 |
> f"fun:{expected_argv}", |
| 1380 |
> f"module:{expected_argv}", |
| 1381 |
> f"fun:{expected_argv}", |
| 1382 |
> '', |
| 1383 |
> ]) |
| 1384 |
> |
| 1385 |
|