Skip to content

Commit 08e4266

Browse files
authored
updated to 3.12.5, 3.13.0rc1, 7.3.17 (#192)
1 parent 1bbf5f3 commit 08e4266

File tree

20 files changed

+372
-27
lines changed

20 files changed

+372
-27
lines changed

py3.12/README_MODS

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ diff Python-3.12.0b4/Lib/test/_test_multiprocessing.py Python-3.12.0rc2/Lib/test
11191119
> continue
11201120
>
11211121
# ----------------------------------------------------------------------
1122-
$ diff Python-3.12.0rc2/Lib/test/_test_multiprocessing.py Python-3.12.0rc3/Lib/test/_test_multiprocessing.py
1122+
diff Python-3.12.0rc2/Lib/test/_test_multiprocessing.py Python-3.12.0rc3/Lib/test/_test_multiprocessing.py
11231123
677a678
11241124
> @support.requires_resource('walltime')
11251125
4955a4957
@@ -1575,3 +1575,42 @@ diff Python-3.12.2/Lib/test/_test_multiprocessing.py Python-3.12.3/Lib/test/_tes
15751575
< def test_invalid_shared_memory_cration(self):
15761576
---
15771577
> def test_invalid_shared_memory_creation(self):
1578+
# ----------------------------------------------------------------------
1579+
diff Python-3.12.3/Lib/test/_test_multiprocessing.py Python-3.12.5/Lib/test/_test_multiprocessing.py
1580+
25d24
1581+
< import pathlib
1582+
327,328c326,328
1583+
< sys.executable.encode(), # bytes
1584+
< pathlib.Path(sys.executable) # os.PathLike
1585+
---
1586+
> os.fsencode(sys.executable), # bytes
1587+
> os_helper.FakePath(sys.executable), # os.PathLike
1588+
> os_helper.FakePath(os.fsencode(sys.executable)), # os.PathLike bytes
1589+
1334a1335,1351
1590+
> def test_closed_queue_empty_exceptions(self):
1591+
> # Assert that checking the emptiness of an unused closed queue
1592+
> # does not raise an OSError. The rationale is that q.close() is
1593+
> # a no-op upon construction and becomes effective once the queue
1594+
> # has been used (e.g., by calling q.put()).
1595+
> for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
1596+
> q.close() # this is a no-op since the feeder thread is None
1597+
> q.join_thread() # this is also a no-op
1598+
> self.assertTrue(q.empty())
1599+
>
1600+
> for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
1601+
> q.put('foo') # make sure that the queue is 'used'
1602+
> q.close() # close the feeder thread
1603+
> q.join_thread() # make sure to join the feeder thread
1604+
> with self.assertRaisesRegex(OSError, 'is closed'):
1605+
> q.empty()
1606+
>
1607+
5693a5711,5719
1608+
> def test_empty_exceptions(self):
1609+
> # Assert that checking emptiness of a closed queue raises
1610+
> # an OSError, independently of whether the queue was used
1611+
> # or not. This differs from Queue and JoinableQueue.
1612+
> q = multiprocessing.SimpleQueue()
1613+
> q.close() # close the pipe
1614+
> with self.assertRaisesRegex(OSError, 'is closed'):
1615+
> q.empty()
1616+
>

py3.12/multiprocess/tests/__init__.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import subprocess
2323
import struct
2424
import operator
25-
import pathlib
2625
import pickle #XXX: use dill?
2726
import weakref
2827
import warnings
@@ -331,8 +330,9 @@ def test_set_executable(self):
331330
self.skipTest(f'test not appropriate for {self.TYPE}')
332331
paths = [
333332
sys.executable, # str
334-
sys.executable.encode(), # bytes
335-
pathlib.Path(sys.executable) # os.PathLike
333+
os.fsencode(sys.executable), # bytes
334+
os_helper.FakePath(sys.executable), # os.PathLike
335+
os_helper.FakePath(os.fsencode(sys.executable)), # os.PathLike bytes
336336
]
337337
for path in paths:
338338
self.set_executable(path)
@@ -1340,6 +1340,23 @@ def _on_queue_feeder_error(e, obj):
13401340
self.assertTrue(not_serializable_obj.reduce_was_called)
13411341
self.assertTrue(not_serializable_obj.on_queue_feeder_error_was_called)
13421342

1343+
def test_closed_queue_empty_exceptions(self):
1344+
# Assert that checking the emptiness of an unused closed queue
1345+
# does not raise an OSError. The rationale is that q.close() is
1346+
# a no-op upon construction and becomes effective once the queue
1347+
# has been used (e.g., by calling q.put()).
1348+
for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
1349+
q.close() # this is a no-op since the feeder thread is None
1350+
q.join_thread() # this is also a no-op
1351+
self.assertTrue(q.empty())
1352+
1353+
for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
1354+
q.put('foo') # make sure that the queue is 'used'
1355+
q.close() # close the feeder thread
1356+
q.join_thread() # make sure to join the feeder thread
1357+
with self.assertRaisesRegex(OSError, 'is closed'):
1358+
q.empty()
1359+
13431360
def test_closed_queue_put_get_exceptions(self):
13441361
for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
13451362
q.close()
@@ -5703,6 +5720,15 @@ def _test_empty(cls, queue, child_can_start, parent_can_continue):
57035720
finally:
57045721
parent_can_continue.set()
57055722

5723+
def test_empty_exceptions(self):
5724+
# Assert that checking emptiness of a closed queue raises
5725+
# an OSError, independently of whether the queue was used
5726+
# or not. This differs from Queue and JoinableQueue.
5727+
q = multiprocessing.SimpleQueue()
5728+
q.close() # close the pipe
5729+
with self.assertRaisesRegex(OSError, 'is closed'):
5730+
q.empty()
5731+
57065732
def test_empty(self):
57075733
queue = multiprocessing.SimpleQueue()
57085734
child_can_start = multiprocessing.Event()

py3.13/Modules/_multiprocess/clinic/semaphore.c.h

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ preserve
66
# include "pycore_gc.h" // PyGC_Head
77
# include "pycore_runtime.h" // _Py_ID()
88
#endif
9+
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
910
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
1011

1112
#if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS)
@@ -75,7 +76,9 @@ _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_
7576
}
7677
timeout_obj = args[1];
7778
skip_optional_pos:
79+
Py_BEGIN_CRITICAL_SECTION(self);
7880
return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);
81+
Py_END_CRITICAL_SECTION();
7982

8083
exit:
8184
return return_value;
@@ -100,7 +103,13 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self);
100103
static PyObject *
101104
_multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))
102105
{
103-
return _multiprocessing_SemLock_release_impl(self);
106+
PyObject *return_value = NULL;
107+
108+
Py_BEGIN_CRITICAL_SECTION(self);
109+
return_value = _multiprocessing_SemLock_release_impl(self);
110+
Py_END_CRITICAL_SECTION();
111+
112+
return return_value;
104113
}
105114

106115
#endif /* defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) */
@@ -172,7 +181,9 @@ _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_
172181
}
173182
timeout_obj = args[1];
174183
skip_optional_pos:
184+
Py_BEGIN_CRITICAL_SECTION(self);
175185
return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);
186+
Py_END_CRITICAL_SECTION();
176187

177188
exit:
178189
return return_value;
@@ -197,7 +208,13 @@ _multiprocessing_SemLock_release_impl(SemLockObject *self);
197208
static PyObject *
198209
_multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))
199210
{
200-
return _multiprocessing_SemLock_release_impl(self);
211+
PyObject *return_value = NULL;
212+
213+
Py_BEGIN_CRITICAL_SECTION(self);
214+
return_value = _multiprocessing_SemLock_release_impl(self);
215+
Py_END_CRITICAL_SECTION();
216+
217+
return return_value;
201218
}
202219

203220
#endif /* defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) */
@@ -340,7 +357,13 @@ _multiprocessing_SemLock__count_impl(SemLockObject *self);
340357
static PyObject *
341358
_multiprocessing_SemLock__count(SemLockObject *self, PyObject *Py_UNUSED(ignored))
342359
{
343-
return _multiprocessing_SemLock__count_impl(self);
360+
PyObject *return_value = NULL;
361+
362+
Py_BEGIN_CRITICAL_SECTION(self);
363+
return_value = _multiprocessing_SemLock__count_impl(self);
364+
Py_END_CRITICAL_SECTION();
365+
366+
return return_value;
344367
}
345368

346369
#endif /* defined(HAVE_MP_SEMAPHORE) */
@@ -450,7 +473,13 @@ _multiprocessing_SemLock___enter___impl(SemLockObject *self);
450473
static PyObject *
451474
_multiprocessing_SemLock___enter__(SemLockObject *self, PyObject *Py_UNUSED(ignored))
452475
{
453-
return _multiprocessing_SemLock___enter___impl(self);
476+
PyObject *return_value = NULL;
477+
478+
Py_BEGIN_CRITICAL_SECTION(self);
479+
return_value = _multiprocessing_SemLock___enter___impl(self);
480+
Py_END_CRITICAL_SECTION();
481+
482+
return return_value;
454483
}
455484

456485
#endif /* defined(HAVE_MP_SEMAPHORE) */
@@ -495,7 +524,9 @@ _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py
495524
}
496525
exc_tb = args[2];
497526
skip_optional:
527+
Py_BEGIN_CRITICAL_SECTION(self);
498528
return_value = _multiprocessing_SemLock___exit___impl(self, exc_type, exc_value, exc_tb);
529+
Py_END_CRITICAL_SECTION();
499530

500531
exit:
501532
return return_value;
@@ -542,4 +573,4 @@ _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py
542573
#ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
543574
#define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
544575
#endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */
545-
/*[clinic end generated code: output=d57992037e6770b6 input=a9049054013a1b77]*/
576+
/*[clinic end generated code: output=dea36482d23a355f input=a9049054013a1b77]*/

py3.13/Modules/_multiprocess/multiprocess.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ multiprocess_exec(PyObject *module)
277277
static PyModuleDef_Slot multiprocess_slots[] = {
278278
{Py_mod_exec, multiprocess_exec},
279279
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
280+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
280281
{0, NULL}
281282
};
282283

py3.13/Modules/_multiprocess/posixshmem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
posixshmem - A Python extension that provides shm_open() and shm_unlink()
33
*/
44

5-
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
5+
// Need limited C API version 3.13 for Py_mod_gil
66
#include "pyconfig.h" // Py_GIL_DISABLED
77
#ifndef Py_GIL_DISABLED
8-
# define Py_LIMITED_API 0x030c0000
8+
# define Py_LIMITED_API 0x030d0000
99
#endif
1010

1111
#include <Python.h>
@@ -128,6 +128,7 @@ static PyMethodDef module_methods[ ] = {
128128

129129
static PyModuleDef_Slot module_slots[] = {
130130
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
131+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
131132
{0, NULL}
132133
};
133134

py3.13/Modules/_multiprocess/semaphore.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,19 +682,21 @@ _multiprocess_SemLock__after_fork_impl(SemLockObject *self)
682682
}
683683

684684
/*[clinic input]
685+
@critical_section
685686
_multiprocess.SemLock.__enter__
686687
687688
Enter the semaphore/lock.
688689
[clinic start generated code]*/
689690

690691
static PyObject *
691692
_multiprocess_SemLock___enter___impl(SemLockObject *self)
692-
/*[clinic end generated code: output=beeb2f07c858511f input=c5e27d594284690b]*/
693+
/*[clinic end generated code: output=beeb2f07c858511f input=d35c9860992ee790]*/
693694
{
694695
return _multiprocess_SemLock_acquire_impl(self, 1, Py_None);
695696
}
696697

697698
/*[clinic input]
699+
@critical_section
698700
_multiprocess.SemLock.__exit__
699701
700702
exc_type: object = None
@@ -709,7 +711,7 @@ static PyObject *
709711
_multiprocess_SemLock___exit___impl(SemLockObject *self,
710712
PyObject *exc_type,
711713
PyObject *exc_value, PyObject *exc_tb)
712-
/*[clinic end generated code: output=3b37c1a9f8b91a03 input=7d644b64a89903f8]*/
714+
/*[clinic end generated code: output=3b37c1a9f8b91a03 input=1610c8cc3e0e337e]*/
713715
{
714716
return _multiprocess_SemLock_release_impl(self);
715717
}

0 commit comments

Comments
 (0)