Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 0 additions & 1 deletion Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,6 @@ def test_exec_set_nomemory_hang(self):
self.assertGreater(len(output), 0) # At minimum, should not hang
self.assertIn(b"MemoryError", output)

Comment thread
brijkapadia marked this conversation as resolved.

class NameErrorTests(unittest.TestCase):
def test_name_error_has_name(self):
try:
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_free_threading/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
import copy

from test.support import threading_helper

threading_helper.requires_working_threading(module=True)
class ExceptionTests(unittest.TestCase):
def test_setstate_data_race(self):
E = Exception()

def func():
for i in range(100):
setattr(E, 'x', i)
copy.copy(E)

threading_helper.run_concurrently(func, nthreads=4)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix data race in :meth:`BaseException.__setstate__` when an exception is copied while being mutated.
6 changes: 3 additions & 3 deletions Objects/clinic/exceptions.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ BaseException___reduce___impl(PyBaseExceptionObject *self)
*/

/*[clinic input]
@critical_section
@critical_section state
BaseException.__setstate__
state: object
/
[clinic start generated code]*/

static PyObject *
BaseException___setstate___impl(PyBaseExceptionObject *self, PyObject *state)
/*[clinic end generated code: output=f3834889950453ab input=5524b61cfe9b9856]*/
/*[clinic end generated code: output=f3834889950453ab input=2ddc941f42fc5bf6]*/
{
PyObject *d_key, *d_value;
Py_ssize_t i = 0;
Expand Down
Loading