aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pylifecycle.c
Commit message (Collapse)AuthorAge
* gh-131942: Use the Python-specific `Py_DEBUG` macro rather than `_DEBUG` in ↵Xuehai Pan2025-05-08
| | | | Windows-related C code (GH-131944)
* GH-124715: Move trashcan mechanism into `Py_Dealloc` (GH-132280)Mark Shannon2025-04-30
|
* gh-132661: Implement PEP 750 (#132662)Lysandros Nikolaou2025-04-30
| | | | | | | | | | | | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Wingy <git@wingysam.xyz> Co-authored-by: Koudai Aono <koxudaxi@gmail.com> Co-authored-by: Dave Peck <davepeck@gmail.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Paul Everitt <pauleveritt@me.com> Co-authored-by: sobolevn <mail@sobolevn.me>
* gh-132952: Speed up startup by importing _io instead of io (#132957)Jelle Zijlstra2025-04-28
|
* gh-132776: Revert Moving memoryview XIData Code to memoryobject.c (gh-132960)Eric Snow2025-04-25
| | | This is a partial revert of gh-132821. It resolves the refleak introduced by that PR.
* gh-132776: Cleanup for XIBufferViewType (gh-132821)Eric Snow2025-04-24
| | | | | * add notes * rename XIBufferViewObject to xibufferview * move memoryview XIData code to memoryobject.c
* Fix a typo in Python/pylifecycle.c (#132350)Chu2025-04-10
|
* gh-131738: optimize builtin any/all/tuple calls with a generator expression ↵Irit Katriel2025-03-28
| | | | arg (#131737)
* gh-131238: Add pycore_interpframe_structs.h header (#131553)Victor Stinner2025-03-21
| | | | Add an explicit include to pycore_interpframe_structs.h in pycore_runtime_structs.h to fix a dependency cycle.
* GH-131498: Remove conditional stack effects (GH-131499)Mark Shannon2025-03-20
| | | * Adds some missing #includes
* gh-131238: Remove includes from pycore_interp.h (#131495)Victor Stinner2025-03-20
| | | Remove also now unused includes in C files.
* gh-131238: Remove more includes from pycore_interp.h (#131480)Victor Stinner2025-03-19
|
* GH-131238: Core header refactor (GH-131250)Mark Shannon2025-03-17
| | | | | * Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h * Removes many cross-header dependencies
* gh-124878: Fix race conditions during interpreter finalization (#130649)Sam Gross2025-03-06
| | | | | | | | | | | | | | | | | | | | 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-25
| | | | | | | | 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-129354: Fix grammar in PyErr_FormatUnraisable() (#129475)Victor Stinner2025-01-31
| | | Replace "on verb+ing" with "while verb+ing".
* gh-128911: Add PyImport_ImportModuleAttr() function (#128912)Victor Stinner2025-01-30
| | | | | | | | | | | Add PyImport_ImportModuleAttr() and PyImport_ImportModuleAttrString() functions. * Add unit tests. * Replace _PyImport_GetModuleAttr() with PyImport_ImportModuleAttr(). * Replace _PyImport_GetModuleAttrString() with PyImport_ImportModuleAttrString(). * Remove "pycore_import.h" includes, no longer needed.
* GH-126599: Remove the PyOptimizer API (GH-129194)Brandt Bucher2025-01-28
|
* gh-129185: Simplify PyTraceMalloc_Track() (#129256)Victor Stinner2025-01-24
| | | | | | | | | | Since tracemalloc uses PyMutex, it becomes safe to use TABLES_LOCK() even after _PyTraceMalloc_Fini(): remove the "pre-check" in PyTraceMalloc_Track() and PyTraceMalloc_Untrack(). PyTraceMalloc_Untrack() no longer needs to acquire the GIL. _PyTraceMalloc_Fini() can be called earlier during Python finalization.
* gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191)Victor Stinner2025-01-23
| | | | | | | | | Support calling PyTraceMalloc_Track() and PyTraceMalloc_Untrack() during late Python finalization. * Call _PyTraceMalloc_Fini() later in Python finalization. * Test also PyTraceMalloc_Untrack() without the GIL * PyTraceMalloc_Untrack() now gets the GIL. * Test also PyTraceMalloc_Untrack() in test_tracemalloc_track_race().
* GH-91048: Add utils for capturing async call stack for asyncio programs and ↵Yury Selivanov2025-01-22
| | | | | | | | | | | enable profiling (#124640) Signed-off-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com> Co-authored-by: Jacob Coffee <jacob@z7x.org> Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* gh-129033: Remove _PyInterpreterState_SetConfig() function (#129048)Victor Stinner2025-01-20
| | | | | | Remove _PyInterpreterState_GetConfigCopy() and _PyInterpreterState_SetConfig() private functions. PEP 741 "Python Configuration C API" added a better public C API: PyConfig_Get() and PyConfig_Set().
* gh-129033: Remove _Py_InitializeMain() function (#129034)Victor Stinner2025-01-20
| | | Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* gh-128679: Redesign tracemalloc locking (#128888)Victor Stinner2025-01-15
| | | | | | | | | * Use TABLES_LOCK() to protect 'tracemalloc_config.tracing'. * Hold TABLES_LOCK() longer while accessing tables. * tracemalloc_realloc() and tracemalloc_free() no longer remove the trace on reentrant call. * _PyTraceMalloc_Stop() unregisters _PyTraceMalloc_TraceRef(). * _PyTraceMalloc_GetTraces() sets the reentrant flag. * tracemalloc_clear_traces_unlocked() sets the reentrant flag.
* gh-128400: Only show the current thread in `Py_FatalError` on the ↵Peter Bierma2025-01-13
| | | | free-threaded build (#128758)
* gh-128146: Exclude os/log.h import on older macOS versions. (#128165)Russell Keith-Magee2025-01-07
| | | | Reworks the handling of Apple system log handling to account for older macOS versions that don't provide os-log.
* gh-126925: Modify how iOS test results are gathered (#127592)Russell Keith-Magee2024-12-09
| | | | | | | Adds a `use_system_log` config item to enable stdout/stderr redirection for Apple platforms. This log streaming is then used by a new iOS test runner script, allowing the display of test suite output at runtime. The iOS test runner script can be used by any Python project, not just the CPython test suite.
* gh-126881: fix finalization of dtoa state (#126904)Kumar Aditya2024-11-29
|
* gh-126255: Ignore warning about JIT being deactivated when perf support is ↵mpage2024-11-01
| | | | | | | | | | | active in `test_embed.InitConfigTests.test_initconfig_api` (#126302) Temporarily ignore warnings about JIT deactivation when perf support is active. This will be reverted as soon as a way is found to determine at run time whether the interpreter was built with JIT. Currently, this is not possible on Windows. Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-124855: Don't allow the JIT and perf support to be active at the same ↵Pablo Galindo Salgado2024-10-30
| | | | time (#124856)
* gh-125286: Share the Main Refchain With Legacy Interpreters (gh-125709)Eric Snow2024-10-23
| | | | | They used to be shared, before 3.12. Returning to sharing them resolves a failure on Py_TRACE_REFS builds. Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-125604: Move _Py_AuditHookEntry, etc. Out of pycore_runtime.h (gh-125605)Eric Snow2024-10-18
| | | | | | | | | | | | This is essentially a cleanup, moving a handful of API declarations to the header files where they fit best, creating new ones when needed. We do the following: * add pycore_debug_offsets.h and move _Py_DebugOffsets, etc. there * inline struct _getargs_runtime_state and struct _gilstate_runtime_state in _PyRuntimeState * move struct _reftracer_runtime_state to the existing pycore_object_state.h * add pycore_audit.h and move to it _Py_AuditHookEntry , _PySys_Audit(), and _PySys_ClearAuditHooks * add audit.h and cpython/audit.h and move the existing audit-related API there *move the perfmap/trampoline API from cpython/sysmodule.h to cpython/ceval.h, and remove the now-empty cpython/sysmodule.h
* gh-124218: Use per-thread refcounts for code objects (#125216)Sam Gross2024-10-15
| | | | | | | Use per-thread refcounting for the reference from function objects to their corresponding code object. This can be a source of contention when frequently creating nested functions. Deferred refcounting alone isn't a great fit here because these references are on the heap and may be modified by other libraries.
* gh-87135: Hang non-main threads that attempt to acquire the GIL during ↵Jeremy Maitin-Shepard2024-10-02
| | | | | | | finalization (GH-105805) Instead of surprise crashes and memory corruption, we now hang threads that attempt to re-enter the Python interpreter after Python runtime finalization has started. These are typically daemon threads (our long standing mis-feature) but could also be threads spawned by extension modules that then try to call into Python. This marks the `PyThread_exit_thread` public C API as deprecated as there is no plausible safe way to accomplish that on any supported platform in the face of things like C++ code with finalizers anywhere on a thread's stack. Doing this was the least bad option. Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-124218: Refactor per-thread reference counting (#124844)Sam Gross2024-10-01
| | | | | | | Currently, we only use per-thread reference counting for heap type objects and the naming reflects that. We will extend it to a few additional types in an upcoming change to avoid scaling bottlenecks when creating nested functions. Rename some of the files and functions in preparation for this change.
* gh-119180: No longer set `__annotations__` in `__main__` (#124634)Jelle Zijlstra2024-09-27
|
* Add debug offsets for free threaded builds (#123041)Pablo Galindo Salgado2024-08-15
|
* gh-122697: Fix free-threading memory leaks at shutdown (#122703)Sam Gross2024-08-08
| | | | | | | | | | | | | | | We were not properly accounting for interpreter memory leaks at shutdown and had two sources of leaks: * Objects that use deferred reference counting and were reachable via static types outlive the final GC. We now disable deferred reference counting on all objects if we are calling the GC due to interpreter shutdown. * `_PyMem_FreeDelayed` did not properly check for interpreter shutdown so we had some memory blocks that were enqueued to be freed, but never actually freed. * `_PyType_FinalizeIdPool` wasn't called at interpreter shutdown.
* gh-100240: Use a consistent implementation for freelists (#121934)Sam Gross2024-07-22
| | | | | | | | This combines and updates our freelist handling to use a consistent implementation. Objects in the freelist are linked together using the first word of memory block. If configured with freelists disabled, these operations are essentially no-ops.
* gh-120837: Update _Py_DumpExtensionModules to be async-signal-safe (gh-121051)Donghee Na2024-06-28
|
* gh-113433: Automatically Clean Up Subinterpreters in Py_Finalize() (gh-121060)Eric Snow2024-06-26
| | | This change makes things a little less painful for some users. It also fixes a failing assert (gh-120765), by making sure all subinterpreters are destroyed before the main interpreter. As part of that, we make sure Py_Finalize() always runs with the main interpreter active.
* gh-120642: Move private PyCode APIs to the internal C API (#120643)Victor Stinner2024-06-26
| | | | | | | | | | | | | | | * Move _Py_CODEUNIT and related functions to pycore_code.h. * Move _Py_BackoffCounter to pycore_backoff.h. * Move Include/cpython/optimizer.h content to pycore_optimizer.h. * Remove Include/cpython/optimizer.h. * Remove PyUnstable_Replace_Executor(). Rename functions: * PyUnstable_GetExecutor() => _Py_GetExecutor() * PyUnstable_GetOptimizer() => _Py_GetOptimizer() * PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer() * PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter() * PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()
* gh-120838: Add _PyThreadState_WHENCE_FINI (gh-121010)Eric Snow2024-06-25
| | | | | We also add _PyThreadState_NewBound() and drop _PyThreadState_SetWhence(). This change only affects internal API.
* gh-120834: fix type of *_iframe field in _PyGenObject_HEAD declaration (#120835)Irit Katriel2024-06-24
|
* gh-120161: Fix a Crash in the _datetime Module (gh-120182)Eric Snow2024-06-14
| | | | | | | In gh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch.
* gh-111499: Fix PYTHONMALLOCSTATS at Python exit (#120021)Victor Stinner2024-06-04
| | | | Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted.
* gh-118527: Intern code consts in free-threaded build (#118667)Sam Gross2024-05-06
| | | | | | We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
* gh-118518: Allow perf to work without frame pointers (#112254)Pablo Galindo Salgado2024-05-05
|
* gh-118527: Use `_Py_ID(__main__)` for main module name (#118528)Sam Gross2024-05-03
| | | | | Most module names are interned and immortalized, but the main module was not. This partially addresses a scaling bottleneck in the free-threaded when creating closure concurrently in the main module.
* gh-118335: Configure Tier 2 interpreter at build time (#118339)Guido van Rossum2024-04-30
| | | | | | | | | | | | | | | | | | | | | | The code for Tier 2 is now only compiled when configured with `--enable-experimental-jit[=yes|interpreter]`. We drop support for `PYTHON_UOPS` and -`Xuops`, but you can disable the interpreter or JIT at runtime by setting `PYTHON_JIT=0`. You can also build it without enabling it by default using `--enable-experimental-jit=yes-off`; enable with `PYTHON_JIT=1`. On Windows, the `build.bat` script supports `--experimental-jit`, `--experimental-jit-off`, `--experimental-interpreter`. In the C code, `_Py_JIT` is defined as before when the JIT is enabled; the new variable `_Py_TIER2` is defined when the JIT *or* the interpreter is enabled. It is actually a bitmask: 1: JIT; 2: default-off; 4: interpreter.