Skip to content
Merged
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
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 :class:`BaseException` when an exception is copied while being mutated.
4 changes: 2 additions & 2 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=f9b1aea70382cdb6]*/
{
PyObject *d_key, *d_value;
Py_ssize_t i = 0;
Expand Down
Loading