summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_free_threading
Commit message (Collapse)AuthorAgeFilesLines
* gh-127065: Make methodcaller thread-safe and re-entrant (GH-127746)Pieter Eendebak2024-12-111-0/+33
| | | | | | | | | | | The function `operator.methodcaller` was not thread-safe since the additional of the vectorcall method in gh-89013. In the free threading build the issue is easy to trigger, for the normal build harder. This makes the `methodcaller` safe by: * Replacing the lazy initialization with initialization in the constructor. * Using a stack allocated space for the vectorcall arguments and falling back to `tp_call` for calls with more than 8 arguments.
* gh-127271: Replace use of PyCell_GET/SET (gh-127272)Neil Schemenauer2024-12-031-0/+134
| | | | | | | | | | | | | | | | | | * Replace uses of `PyCell_GET` and `PyCell_SET`. These macros are not safe to use in the free-threaded build. Use `PyCell_GetRef()` and `PyCell_SetTakeRef()` instead. * Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some code restructuring was required, e.g. `frame_get_var()` returns a strong ref now. * Add critical sections to `PyCell_GET` and `PyCell_SET`. * Move critical_section.h earlier in the Python.h file. * Add `PyCell_GET` to the free-threading howto table of APIs that return borrowed refs. * Add additional unit tests for free-threading.
* gh-117657: TSAN Fix races in `PyMember_Get` and `PyMember_Set` for C ↵Daniele Parmeggiani2024-12-031-0/+244
| | | | extensions (GH-123211)
* gh-127316: fix incorrect assertion in setting `__class__` in free-threading ↵Kumar Aditya2024-11-291-0/+15
| | | | (#127399)
* gh-124470: Fix crash when reading from object instance dictionary while ↵Dino Viehland2024-11-211-0/+64
| | | | | replacing it (#122489) Delay free a dictionary when replacing it
* gh-127020: Make `PyCode_GetCode` thread-safe for free threading (#127043)Sam Gross2024-11-211-0/+30
| | | | Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe.
* gh-125859: Fix crash when `gc.get_objects` is called during GC (#125882)Sam Gross2024-10-241-0/+61
| | | | | | | | | 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.
* gh-124296: Remove private dictionary version tag (PEP 699) (#124472)Sam Gross2024-10-011-35/+0
|
* gh-124402: Speed up test_free_threading and test_super (#124491)Victor Stinner2024-09-263-47/+40
| | | | | | | * 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.
* gh-124402: Require cpu resource in test_free_threading (#124438)Victor Stinner2024-09-243-0/+8
| | | Require the 'cpu' test resource on slow test_free_threading tests.
* Fix typos (#123775)algonell2024-09-091-1/+1
|
* gh-123271: Make builtin zip method safe under free-threading (#123272)Pieter Eendebak2024-08-271-0/+41
| | | | | | | | | | | | | | | | The `zip_next` function uses a common optimization technique for methods that generate tuples. The iterator maintains an internal reference to the returned tuple. When the method is called again, it checks if the internal tuple's reference count is 1. If so, the tuple can be reused. However, this approach is not safe under the free-threading build: after checking the reference count, another thread may perform the same check and also reuse the tuple. This can result in a double decref on the items of the replaced tuple and a double incref (memory leak) on the items of the tuple being set. This adds a function, `_PyObject_IsUniquelyReferenced` that encapsulates the stricter logic necessary for the free-threaded build: the internal tuple must be owned by the current thread, have a local refcount of one, and a shared refcount of zero.
* gh-120317: Lock around global state in the tokenize module (#120318)Lysandros Nikolaou2024-07-161-0/+57
| | | Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-120198: Stop the world when setting __class__ on free-threaded build ↵Ken Jin2024-07-101-1/+1
| | | | (GH-120672)
* gh-120659: Skip `test_freethreading` with GIL (#120660)Nice Zombies2024-06-181-0/+4
|
* gh-120417: Remove unused imports in tests (part 2) (#120630)Victor Stinner2024-06-172-2/+1
|
* gh-117657: Fix `__slots__` thread safety in free-threaded build (#119368)Daniele Parmeggiani2024-06-171-0/+43
| | | | Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`. These functions implement `__slots__` accesses for Python objects.
* gh-120579: Guard `_testcapi` import in `test_free_threading` (#120580)Nikita Sobolev2024-06-161-1/+6
|
* gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)Ken Jin2024-06-121-0/+26
| | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
* gh-120198: Fix race condition when editing __class__ with an audit hook ↵Ken Jin2024-06-111-0/+1
| | | | active (GH-120195)
* gh-119247: Add macros to use PySequence_Fast safely in free-threaded build ↵Josh {*()} Rosenberg2024-05-221-0/+75
| | | | | | | | (#119315) 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.
* gh-112075: use per-thread dict version pool (#118676)Dino Viehland2024-05-071-0/+36
| | | use thread state set of dict versions
* gh-118362: Skip tests when threading isn't available (#118666)Dino Viehland2024-05-063-16/+16
| | | | | * Skip tests when threads aren't available * Use ThreadPoolExecutor
* gh-112075: Fix race in constructing dict for instance (#118499)Dino Viehland2024-05-061-0/+141
|
* gh-118415: Fix issues with local tracing being enabled/disabled on a ↵Dino Viehland2024-05-061-13/+26
| | | | function (#118496)
* gh-118362: Fix thread safety around lookups from the type cache in the face ↵Dino Viehland2024-05-061-0/+112
| | | | | | | 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
* gh-117657: Fix TSAN list set failure (#118260)Dino Viehland2024-05-021-0/+80
| | | | | | | | | | | * Fix TSAN list set failure * Relaxed atomic is sufficient, add targetted test * More list * Remove atomic assign in list * Fixup white space
* gh-116818: Make `sys.settrace`, `sys.setprofile`, and monitoring thread-safe ↵Dino Viehland2024-04-192-0/+239
(#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.