summaryrefslogtreecommitdiffstats
path: root/Modules/_threadmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* GH-116946: revert eliminate the need for the GC in the `_thread.lock` and ↵Kumar Aditya2025-11-121-15/+7
| | | | | | | `_thread.RLock` (#141448) Revert "GH-116946: eliminate the need for the GC in the `_thread.lock` and `_thread.RLock` (#141268)" This reverts commit fbebca289d811669fc1980e3a135325b8542a846.
* GH-116946: eliminate the need for the GC in the `_thread.lock` and ↵Sergey Miryanov2025-11-121-7/+15
| | | | `_thread.RLock` (#141268)
* gh-116946: partial revert gh-139073 for thread handle type (#139474)Kumar Aditya2025-10-011-1/+3
|
* gh-116946: remove unnecessary gc from immutable types (#139073)Sergey Miryanov2025-10-011-3/+1
|
* gh-136003: Skip non-daemon threads when exceptions occur during finalization ↵Peter Bierma2025-09-181-3/+1
| | | | | (GH-139129) During finalization, we need to mark all non-daemon threads as daemon to quickly shut down threads when sending CTRL^C to the process. This was a minor regression from GH-136004.
* gh-136003: Execute pre-finalization callbacks in a loop (GH-136004)Peter Bierma2025-09-181-3/+4
|
* gh-137017: Ensure `Thread.is_alive()` only returns False after the ↵Abdul2025-09-151-0/+3
| | | | underlying OS thread exits (gh-137315)
* gh-138004: Fix setting a thread name on OpenIndiana (GH-138017)jadonduff2025-09-021-3/+6
| | | | | | | | Encode Solaris/Illumos thread names to ASCII, since OpenIndiana does not support non-ASCII names. Add tests for setting non-ASCII name for the main thread. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-138342: Use a common utility for visiting an object's type (GH-138343)Peter Bierma2025-09-011-24/+3
| | | Add `_PyObject_VisitType` in place of `tp_traverse` functions that only visit the object's type.
* gh-137808: use argument clinic for `_thread.lock` and `_thread.RLock` (#137809)Kumar Aditya2025-08-151-201/+261
|
* Revert "gh-112068: C API: Add support of nullable arguments in PyArg_Parse ↵Serhiy Storchaka2025-07-221-5/+13
| | | | (GH-121303)" (#136991)
* gh-136549: Fix signature of threading.excepthook() (GH-136559)Serhiy Storchaka2025-07-121-1/+1
|
* gh-87135: threading.Lock: Raise rather than hang on Python finalization ↵Petr Viktorin2025-07-011-4/+14
| | | | | | | | (GH-135991) After Python finalization gets to the point where no other thread can attach thread state, attempting to acquire a Python lock must hang. Raise PythonFinalizationError instead of hanging.
* gh-135607: remove null checking of weakref list in dealloc of extension ↵Xuanteng Huang2025-06-301-3/+1
| | | | | | modules and objects (#135614) Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)Serhiy Storchaka2025-05-281-2/+1
| | | | | Add functions PySys_GetAttr(), PySys_GetAttrString(), PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
* gh-134381: Fix RuntimeError when starting not-yet started Thread after fork ↵Jiucheng(Oliver)2025-05-231-0/+6
| | | | (gh-134514)
* gh-134322: Fix `repr(threading.RLock)` (#134389)Duprat2025-05-221-1/+7
| | | Fix the `__repr__` value of `threading.RLock` from `_thread` module, when just created.
* gh-134323: Fix the new `threading.RLock.locked` method (#134368)Duprat2025-05-221-2/+8
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-134087: enforce signature of `threading.RLock` (#134178)Bénédikt Tran2025-05-191-39/+43
| | | | - Reject positional and keyword arguments in `_thread.RLock.__new__`. - Convert `_thread.lock.__new__` to AC.
* gh-87135: Raise PythonFinalizationError when joining a blocked daemon thread ↵Petr Viktorin2025-04-281-5/+15
| | | | | | | | | | | | | | | | (gh-130402) If `Py_IsFinalizing()` is true, non-daemon threads (other than the current one) are done, and daemon threads are prevented from running, so they cannot finalize themselves and become done. Joining them (without timeout) would block forever. Raise PythonFinalizationError instead of hanging. Raise even when a timeout is given, for consistency with trying to join your own thread. See gh-123940 for a use case: calling `join()` from `__del__`. This is ill-advised, but an exception should at least make it easier to diagnose.
* gh-112068: C API: Add support of nullable arguments in PyArg_Parse (GH-121303)Serhiy Storchaka2025-04-081-13/+5
|
* gh-115942: Add `locked` to several multiprocessing locks (#115944)sobolevn2025-04-081-0/+15
| | | | Co-authored-by: mpage <mpage@cs.stanford.edu> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
* gh-111178: Fix function signature for test_threading (#131663)Victor Stinner2025-03-241-2/+3
|
* gh-131238: Remove pycore_object_deferred.h from pycore_object.h (#131549)Victor Stinner2025-03-211-1/+2
| | | Remove also pycore_function.h from pycore_typeobject.h.
* gh-131268: Implement thread names on OpenBSD (#131528)Xavier G.2025-03-211-5/+22
|
* GH-131238: More refactoring of core header files (GH-131351)Mark Shannon2025-03-171-0/+1
| | | | Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
* gh-111178: Fix function signatures to fix undefined behavior (#131191)Victor Stinner2025-03-141-3/+3
|
* gh-111178: Fix function signatures in misc files (#131180)Victor Stinner2025-03-131-2/+3
|
* gh-124878: Fix race conditions during interpreter finalization (#130649)Sam Gross2025-03-061-3/+0
| | | | | | | | | | | | | | | | | | | | The PyThreadState field gains a reference count field to avoid issues with PyThreadState being a dangling pointer to freed memory. The refcount starts with a value of two: one reference is owned by the interpreter's linked list of thread states and one reference is owned by the OS thread. The reference count is decremented when the thread state is removed from the interpreter's linked list and before the OS thread calls `PyThread_hang_thread()`. The thread that decrements it to zero frees the `PyThreadState` memory. The `holds_gil` field is moved out of the `_status` bit field, to avoid a data race where on thread calls `PyThreadState_Clear()`, modifying the `_status` bit field while the OS thread reads `holds_gil` when attempting to acquire the GIL. The `PyThreadState.state` field now has `_Py_THREAD_SHUTTING_DOWN` as a possible value. This corresponds to the `_PyThreadState_MustExit()` check. This avoids race conditions in the free threading build when checking `_PyThreadState_MustExit()`.
* gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)Serhiy Storchaka2025-02-251-6/+6
| | | | | | | | The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
* gh-111178: fix UBSan failures in `Modules/_threadmodule.c` (GH-129794)Bénédikt Tran2025-02-241-76/+83
| | | | | | | | | | Fix UBSan failures for `PyThreadHandleObject`, `lockobject`, `rlockobject`, `localdummyobject`, `localobject` Add safe casts Clean up module functions Use semantically correct parameter names
* gh-129354: Use PyErr_FormatUnraisable() function (#129518)Victor Stinner2025-01-311-16/+27
| | | Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().
* gh-59705: Make PYTHREAD_NAME_MAXLEN macro private (#128945)Victor Stinner2025-01-181-10/+10
| | | Rename PYTHREAD_NAME_MAXLEN to _PYTHREAD_NAME_MAXLEN.
* gh-59705: Implement _thread.set_name() on Windows (#128675)Victor Stinner2025-01-171-2/+81
| | | | | | | | | | Implement set_name() with SetThreadDescription() and _get_name() with GetThreadDescription(). If SetThreadDescription() or GetThreadDescription() is not available in kernelbase.dll, delete the method when the _thread module is imported. Truncate the thread name to 32766 characters. Co-authored-by: Eryk Sun <eryksun@gmail.com>
* gh-128691: Use deferred reference counting on `_thread._local` (#128693)Sam Gross2025-01-101-0/+4
| | | | | This change, along with the LOAD_ATTR specializations, makes the "thread_local_read" micro benchmark in Tools/ftscalingbench/ftscalingbench.py scale well to multiple threads.
* gh-128279: Enhance the NetBSD compatibility for thread naming (#128280)Furkan Onder2024-12-281-0/+3
| | | Enhance NetBSD compatibility for thread naming in _threadmodule.c.
* gh-59705: Set OS thread name when Thread.name is changed (#127702)Victor Stinner2024-12-101-2/+1
| | | Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-59705: Add _thread.set_name() function (#127338)Victor Stinner2024-12-061-0/+108
| | | | | | | | | | | On Linux, threading.Thread now sets the thread name to the operating system. * configure now checks if pthread_getname_np() and pthread_setname_np() functions are available. * Add PYTHREAD_NAME_MAXLEN macro. * Add _thread._NAME_MAXLEN constant for test_threading. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-127190: Fix local_setattro() error handling (#127366)Victor Stinner2024-11-281-1/+1
| | | | Don't make the assumption that the 'name' argument is a string. Use repr() to format the 'name' argument instead.
* gh-109746: Make _thread.start_new_thread delete state of new thread on its ↵Radislav Chugunov2024-11-221-0/+1
| | | | | | | | | | startup failure (GH-109761) If Python fails to start newly created thread due to failure of underlying PyThread_start_new_thread() call, its state should be removed from interpreter' thread states list to avoid its double cleanup. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-125139: use `_PyRecursiveMutex` in `_thread.RLock` (#125144)Kumar Aditya2024-10-141-118/+33
|
* gh-117721: use PyMutex in `_thread.lock` (#125110)Kumar Aditya2024-10-081-45/+11
|
* gh-111178: Fix function signatures in _threadmodule.c (#124964)Victor Stinner2024-10-041-49/+70
|
* Fix typos (#123775)algonell2024-09-091-2/+2
|
* gh-120973: Fix thread-safety issues with `threading.local` (#121655)mpage2024-07-191-150/+234
| | | | | | This is a small refactoring to the current design that allows us to avoid manually iterating over threads. This should also fix gh-118490.
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+1
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-118332: Fix deadlock involving stop the world (#118412)Sam Gross2024-04-301-1/+2
| | | | | | Avoid detaching thread state when stopping the world. When re-attaching the thread state, the thread would attempt to resume the top-most critical section, which might now be held by a thread paused for our stop-the-world request.
* gh-117764: Add signatures and improve docstrings in the _thread module ↵Serhiy Storchaka2024-04-121-46/+126
| | | | (GH-117772)
* gh-113964: Don't prevent new threads until all non-daemon threads exit (#116677)Sam Gross2024-03-191-1/+1
| | | | | | | | | | Starting in Python 3.12, we prevented calling fork() and starting new threads during interpreter finalization (shutdown). This has led to a number of regressions and flaky tests. We should not prevent starting new threads (or `fork()`) until all non-daemon threads exit and finalization starts in earnest. This changes the checks to use `_PyInterpreterState_GetFinalizing(interp)`, which is set immediately before terminating non-daemon threads.
* gh-116915: Make `_thread._ThreadHandle` support GC (#116934)mpage2024-03-181-3/+13
| | | | | | Even though it has no internal references to Python objects it still has a reference to its type by virtue of being a heap type. We need to provide a traverse function that visits the type, but we do not need to provide a clear function.