Commit Graph

24 Commits

Author SHA1 Message Date
Sam Gross e1cc789531
gh-132869: Fix crash in `_PyObject_TryGetInstanceAttribute` (#133700)
This fixes a crash in `_PyObject_TryGetInstanceAttribute` due to the use
of `_PyDictKeys_StringLookup` on an unlocked dictionary that may be
concurrently modified.

The underlying bug was already fixed in 3.14 and the main branch.

(partially cherry picked from commit 1b15c89a17)
2025-05-14 12:47:34 +09:00
Xuanteng Huang bb6f3c3769
[3.13] gh-128714: Fix function object races in `__annotate__`, `__annotations__` and `__type_params__` in free-threading build (GH-129016) (#129729)
* gh-128714: Fix function object races in `__annotate__`, `__annotations__` and `__type_params__` in  free-threading build (#129016)

(cherry picked from commit 55f17b77c3)

---------

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-02-23 21:49:55 -05:00
Sam Gross ee12a3482d
[3.13] gh-129967: Fix race condition in `repr(set)` (gh-129978) (gh-130020)
The call to `PySequence_List()` could temporarily unlock and relock the
set, allowing the items to be cleared and return the incorrect
notation `{}` for a empty set (it should be `set()`).

(cherry picked from commit a7427f2db9)

Co-authored-by: T. Wouters <thomas@python.org>
2025-02-11 18:18:12 -05:00
Miss Islington (bot) 2f56c68dec
[3.13] gh-127316: fix incorrect assertion in setting `__class__` in free-threading (GH-127399) (#127422)
gh-127316: fix incorrect assertion in setting `__class__` in free-threading (GH-127399)
(cherry picked from commit 45c5cba318)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-11-29 16:36:44 +00:00
Miss Islington (bot) c74331413e
[3.13] gh-127020: Make `PyCode_GetCode` thread-safe for free threading (GH-127043) (GH-127107)
Some fields in PyCodeObject are lazily initialized. Use atomics and
critical sections to make their initializations and accesses thread-safe.
(cherry picked from commit 3926842117)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-11-21 16:27:36 +00:00
Miss Islington (bot) 5c2696bc26
[3.13] gh-125859: Fix crash when `gc.get_objects` is called during GC (GH-125882) (GH-125921)
This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is
called during a GC in the free threading build.

Switch to `_PyObjectStack` to avoid corrupting the `struct worklist`
linked list maintained by the GC. Also, don't return objects that are frozen
(`gc.freeze()`) or in the process of being collected to more closely match
the behavior of the default build.
(cherry picked from commit e545ead66c)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-10-24 14:08:15 +00:00
Victor Stinner d432fa43b9
[3.13] Fix typos (#123775) (#123866)
Fix typos (#123775)

(cherry picked from commit 9017b95ff2)

Co-authored-by: algonell <algonell@gmail.com>
2024-10-07 23:44:31 +02:00
Victor Stinner 632844694e
[3.13] gh-124402: Speed up test_free_threading and test_super (#124491) (#124585)
gh-124402: Speed up test_free_threading and test_super (#124491)

* Reduce the number of iterations and the number of threads so a
  whole test file takes less than a minute.
* Refactor test_racing_iter_extend() to remove two levels of
  indentation.
* test_monitoring() uses a sleep of 100 ms instead of 1 second.

(cherry picked from commit 0387c34f7c)
2024-09-26 13:44:36 -07:00
Victor Stinner 5615351a4b
[3.13] gh-124402: Require cpu resource in test_free_threading (#124438) (#124439)
gh-124402: Require cpu resource in test_free_threading (#124438)

Require the 'cpu' test resource on slow test_free_threading tests.

(cherry picked from commit 38a5beb12a)
2024-09-24 11:26:02 -07:00
Miss Islington (bot) e45c61f736
[3.13] gh-120317: Lock around global state in the tokenize module (GH-120318) (#121841)
(cherry picked from commit 8549559f38)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2024-07-16 10:03:47 +00:00
Ken Jin cd74ed0a71
[3.13] gh-120198: Stop the world when setting __class__ on free-threaded build (#121591)
(cherry-picked from commit 3bfc9c8)
2024-07-12 19:35:53 +08:00
Miss Islington (bot) 4f4973d740
[3.13] gh-120659: Skip `test_freethreading` with GIL (GH-120660) (#120694)
gh-120659: Skip `test_freethreading` with GIL (GH-120660)
(cherry picked from commit 360f14a493)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
2024-06-18 14:46:29 +00:00
Miss Islington (bot) 396f8b0b98
[3.13] gh-117657: Fix `__slots__` thread safety in free-threaded build (GH-119368) (#120655)
Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`.
These functions implement `__slots__` accesses for Python objects.
(cherry picked from commit 362cd2680b)

Co-authored-by: Daniele Parmeggiani <8658291+dpdani@users.noreply.github.com>
2024-06-17 19:12:25 +00:00
Miss Islington (bot) f2a4540c4f
[3.13] gh-120579: Guard `_testcapi` import in `test_free_threading` (GH-120580) (#120583)
gh-120579: Guard `_testcapi` import in `test_free_threading` (GH-120580)
(cherry picked from commit 0c0348adbf)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-06-16 08:50:33 +00:00
Miss Islington (bot) 91c4444d22
[3.13] gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165) (GH-120403)
gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)
(cherry picked from commit e16aed63f6)

Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
2024-06-12 21:37:26 +08:00
Miss Islington (bot) a6c4080aaa
gh-120198: Fix race condition when editing __class__ with an audit hook active (GH-120195)
(cherry picked from commit 203565b2f9)

Co-authored-by: Ken Jin <kenjin@python.org>
2024-06-11 19:35:49 +00:00
Miss Islington (bot) 08416065a7
[3.13] gh-119247: Add macros to use PySequence_Fast safely in free-threaded build (GH-119315) (#119419)
Add `Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST` and
`Py_END_CRITICAL_SECTION_SEQUENCE_FAST` macros and update `str.join` to use
them. Also add a regression test that would crash reliably without this
patch.
(cherry picked from commit baf347d916)

Co-authored-by: Josh {*()} Rosenberg <26495692+MojoVampire@users.noreply.github.com>
2024-05-22 19:24:02 +00:00
Dino Viehland ff6cbb2503
gh-112075: use per-thread dict version pool (#118676)
use thread state set of dict versions
2024-05-07 00:22:26 +00:00
Dino Viehland e272195b3e
gh-118362: Skip tests when threading isn't available (#118666)
* Skip tests when threads aren't available

* Use ThreadPoolExecutor
2024-05-06 16:45:04 -07:00
Dino Viehland 636b8d94c9
gh-112075: Fix race in constructing dict for instance (#118499) 2024-05-06 23:31:09 +00:00
Dino Viehland 00d913c671
gh-118415: Fix issues with local tracing being enabled/disabled on a function (#118496) 2024-05-06 13:06:09 -07:00
Dino Viehland 5a1618a2c8
gh-118362: Fix thread safety around lookups from the type cache in the face of concurrent mutators (#118454)
Add _PyType_LookupRef and use incref before setting attribute on type
Makes setting an attribute on a class and signaling type modified atomic
Avoid adding re-entrancy exposing the type cache in an inconsistent state by decrefing after type is updated
2024-05-06 10:50:35 -07:00
Dino Viehland 1e67b9207c
gh-117657: Fix TSAN list set failure (#118260)
* Fix TSAN list set failure

* Relaxed atomic is sufficient, add targetted test

* More list

* Remove atomic assign in list

* Fixup white space
2024-05-02 13:03:05 -07:00
Dino Viehland 07525c9a85
gh-116818: Make `sys.settrace`, `sys.setprofile`, and monitoring thread-safe (#116775)
Makes sys.settrace, sys.setprofile, and monitoring generally thread-safe.

Mostly uses a stop-the-world approach and synchronization around the code object's _co_instrumentation_version.  There may be a little bit of extra synchronization around the monitoring data that's required to be TSAN clean.
2024-04-19 14:47:42 -07:00