Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/multiprocessing/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def _Popen(self):

def __init__(self, group=None, target=None, name=None, args=(), kwargs=None,
*, daemon=None):
assert group is None, 'group argument must be None for now'
if group is not None:
raise TypeError("group argument must be None for now")
if target is not None and not callable(target):
raise TypeError("target must be callable")
count = next(_process_counter)
self._identity = _current_process._identity + (count,)
self._config = _current_process._config.copy()
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ def test_current(self):
self.assertEqual(current.ident, os.getpid())
self.assertEqual(current.exitcode, None)

def test_invalid_args(self):
with self.assertRaisesRegex(TypeError, "group argument must be None"):
self.Process(group="not None")
with self.assertRaisesRegex(TypeError, "target must be callable"):
self.Process(target=123)

@warnings_helper.ignore_fork_in_thread_deprecation_warnings()
def test_set_executable(self):
if self.TYPE == 'threads':
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def func(): pass
thread = threading.Thread(target=func)
self.assertEqual(thread.name, "Thread-5 (func)")

def test_invalid_args(self):
with self.assertRaisesRegex(TypeError, "group argument must be None"):
threading.Thread(group="not None")
with self.assertRaisesRegex(TypeError, "target must be callable"):
threading.Thread(target=123)

def test_args_argument(self):
# bpo-45735: Using list or tuple as *args* in constructor could
# achieve the same effect.
Expand Down
5 changes: 4 additions & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,10 @@ class is implemented.
else to the thread.
"""
assert group is None, "group argument must be None for now"
if group is not None:
raise TypeError("group argument must be None for now")
if target is not None and not callable(target):
raise TypeError("target must be callable")
if kwargs is None:
kwargs = {}
if name:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a segmentation fault in :func:`unicodedata.iter_graphemes` when the iterator is deallocated after being cleared by the garbage collector.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added early validation of the ``target`` argument in :class:`threading.Thread` and :class:`multiprocessing.Process` constructors. If ``target`` is not callable, a :exc:`TypeError` is now raised immediately in the calling thread, resulting in a clearer traceback. Optimized the validation of the reserved ``group`` argument by replacing internal assertions with :exc:`TypeError`.
4 changes: 2 additions & 2 deletions Modules/unicodedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ Segment_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
Py_DECREF(((SegmentObject *)self)->string);
Py_XDECREF(((SegmentObject *)self)->string);
tp->tp_free(self);
Py_DECREF(tp);
}
Expand Down Expand Up @@ -1989,7 +1989,7 @@ GBI_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
Py_DECREF(((GraphemeBreakIterator *)self)->iter.str);
Py_XDECREF(((GraphemeBreakIterator *)self)->iter.str);
tp->tp_free(self);
Py_DECREF(tp);
}
Expand Down
Loading