aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pylifecycle.c
Commit message (Collapse)AuthorAge
...
* 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.
* gh-118422: Fix run_fileexflags() test (#118429)Victor Stinner2024-04-30
| | | | | Don't test the undefined behavior of fileno() on a closed file, but use fstat() as a reliable test if the file was closed or not.
* gh-116622: Redirect stdout and stderr to system log when embedded in an ↵Malcolm Smith2024-04-30
| | | | Android app (#118063)
* gh-117953: Cleanups For fix_up_extension() in import.c (gh-118192)Eric Snow2024-04-24
| | | These are cleanups I've pulled out of gh-118116. Mostly, this change moves code around to align with some future changes and to improve clarity a little. There is one very small change in behavior: we now add the module to the per-interpreter caches after updating the global state, rather than before.
* gh-112069: Add _PySet_NextEntryRef to be thread-safe. (gh-117990)Donghee Na2024-04-19
|
* gh-117649: Raise ImportError for unsupported modules in free-threaded build ↵Sam Gross2024-04-11
| | | | | | | | | | (#117651) The free-threaded build does not currently support the combination of single-phase init modules and non-isolated subinterpreters. Ensure that `check_multi_interp_extensions` is always `True` for subinterpreters in the free-threaded build so that importing these modules raises an `ImportError`.
* gh-76785: Add More Tests to test_interpreters.test_api (gh-117662)Eric Snow2024-04-10
| | | In addition to the increase test coverage, this is a precursor to sorting out how we handle interpreters created directly via the C-API.
* gh-116522: Refactor `_PyThreadState_DeleteExcept` (#117131)Sam Gross2024-03-21
| | | | | | | | | | | Split `_PyThreadState_DeleteExcept` into two functions: - `_PyThreadState_RemoveExcept` removes all thread states other than one passed as an argument. It returns the removed thread states as a linked list. - `_PyThreadState_DeleteList` deletes those dead thread states. It may call destructors, so we want to "start the world" before calling `_PyThreadState_DeleteList` to avoid potential deadlocks.
* gh-115754: Add Py_GetConstant() function (#116883)Victor Stinner2024-03-21
| | | | | | | | | | | | Add Py_GetConstant() and Py_GetConstantBorrowed() functions. In the limited C API version 3.13, getting Py_None, Py_False, Py_True, Py_Ellipsis and Py_NotImplemented singletons is now implemented as function calls at the stable ABI level to hide implementation details. Getting these constants still return borrowed references. Add _testlimitedcapi/object.c and test_capi/test_object.py to test Py_GetConstant() and Py_GetConstantBorrowed() functions.
* gh-105716: Update interp->threads.main After Fork (gh-117049)Eric Snow2024-03-21
| | | | | I missed this in gh-109921. We also update Py_Exit() to call _PyInterpreterState_SetNotRunningMain(), if necessary.
* gh-116522: Stop the world before fork() and during shutdown (#116607)Sam Gross2024-03-21
| | | | | | | | | | | This changes the free-threaded build to perform a stop-the-world pause before deleting other thread states when forking and during shutdown. This fixes some crashes when using multiprocessing and during shutdown when running with `PYTHON_GIL=0`. This also changes `PyOS_BeforeFork` to acquire the runtime lock (i.e., `HEAD_LOCK(&_PyRuntime)`) before forking to ensure that data protected by the runtime lock (and not just the GIL or stop-the-world) is in a consistent state before forking.
* gh-115168: Add pystats counter for invalidated executors (GH-115169)Michael Droettboom2024-02-26
|
* gh-115103: Implement delayed free mechanism for free-threaded builds (#115367)Sam Gross2024-02-20
| | | | | | This adds `_PyMem_FreeDelayed()` and supporting functions. The `_PyMem_FreeDelayed()` function frees memory with the same allocator as `PyMem_Free()`, but after some delay to ensure that concurrent lock-free readers have finished.
* gh-112175: Add `eval_breaker` to `PyThreadState` (#115194)Brett Simmers2024-02-20
| | | | | | | | | | | This change adds an `eval_breaker` field to `PyThreadState`. The primary motivation is for performance in free-threaded builds: with thread-local eval breakers, we can stop a specific thread (e.g., for an async exception) without interrupting other threads. The source of truth for the global instrumentation version is stored in the `instrumentation_version` field in PyInterpreterState. Threads usually read the version from their local `eval_breaker`, where it continues to be colocated with the eval breaker bits.
* GH-112354: Initial implementation of warm up on exits and trace-stitching ↵Mark Shannon2024-02-20
| | | | (GH-114142)
* gh-115503: Fix `run_presite` error handling (#115504)Nikita Sobolev2024-02-16
|
* gh-111968: Rename freelist related struct names to Eric's suggestion (gh-115329)Donghee Na2024-02-14
|
* GH-113710: Backedge counter improvements. (GH-115166)Mark Shannon2024-02-13
|
* GH-113710: Fix updating of dict version tag and add watched dict stats ↵Mark Shannon2024-02-12
| | | | (GH-115221)
* gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists ↵Donghee Na2024-02-10
| | | | (gh-114899)
* GH-113710: Add a "globals to constants" pass (GH-114592)Mark Shannon2024-02-02
| | | Converts specializations of `LOAD_GLOBAL` into constants during tier 2 optimization.
* GH-113464: Add a JIT backend for tier 2 (GH-113465)Brandt Bucher2024-01-28
| | | | | | | Add an option (--enable-experimental-jit for configure-based builds or --experimental-jit for PCbuild-based ones) to build an *experimental* just-in-time compiler, based on copy-and-patch (https://fredrikbk.com/publications/copy-and-patch.pdf). See Tools/jit/README.md for more information on how to install the required build-time tooling.
* gh-113055: Use pointer for interp->obmalloc state (gh-113412)Neil Schemenauer2024-01-26
| | | | | | | | | For interpreters that share state with the main interpreter, this points to the same static memory structure. For interpreters with their own obmalloc state, it is heap allocated. Add free_obmalloc_arenas() which will free the obmalloc arenas and radix tree structures for interpreters with their own obmalloc state. Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-114312: Collect stats for unlikely events (GH-114493)Michael Droettboom2024-01-25
|
* gh-111968: Use per-thread freelists for generator in free-threading (gh-114189)Donghee Na2024-01-18
|
* gh-111968: Use per-thread freelists for PyContext in free-threading (gh-114122)Donghee Na2024-01-16
|
* gh-111968: Use per-thread slice_cache in free-threading (gh-113972)Donghee Na2024-01-16
|
* gh-111968: Use per-thread freelists for tuple in free-threading (gh-113921)Donghee Na2024-01-12
|
* gh-111968: Use per-thread freelists for float in free-threading (gh-113886)Donghee Na2024-01-10
|
* gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API (gh-113584)Donghee Na2024-01-10
|
* gh-112532: Use separate mimalloc heaps for GC objects (gh-113263)Sam Gross2023-12-27
| | | | | | | | | | | | | | | | | | | | | | | | | | * gh-112532: Use separate mimalloc heaps for GC objects In `--disable-gil` builds, we now use four separate heaps in anticipation of using mimalloc to find GC objects when the GIL is disabled. To support this, we also make a few changes to mimalloc: * `mi_heap_t` and `mi_tld_t` initialization is split from allocation. This allows us to have a `mi_tld_t` per-`PyThreadState`, which is important to keep interpreter isolation, since the same OS thread may run in multiple interpreters (using different PyThreadStates.) * Heap abandoning (mi_heap_collect_ex) can now be called from a different thread than the one that created the heap. This is necessary because we may clear and delete the containing PyThreadStates from a different thread during finalization and after fork(). * Use enum instead of defines and guard mimalloc includes. * The enum typedef will be convenient for future PRs that use the type. * Guarding the mimalloc includes allows us to unconditionally include pycore_mimalloc.h from other header files that rely on things like `struct _mimalloc_thread_state`. * Only define _mimalloc_thread_state in Py_GIL_DISABLED builds
* gh-112723: Call `PyThreadState_Clear()` from the correct interpreter (#112776)Sam Gross2023-12-12
| | | | | | | | | | | | | The `PyThreadState_Clear()` function must only be called with the GIL held and must be called from the same interpreter as the passed in thread state. Otherwise, any Python objects on the thread state may be destroyed using the wrong interpreter, leading to memory corruption. This is also important for `Py_GIL_DISABLED` builds because free lists will be associated with PyThreadStates and cleared in `PyThreadState_Clear()`. This fixes two places that called `PyThreadState_Clear()` from the wrong interpreter and adds an assertion to `PyThreadState_Clear()`.
* gh-76785: Fixes for test.support.interpreters (gh-112982)Eric Snow2023-12-12
| | | This involves a number of changes for PEP 734.
* gh-111924: Use PyMutex for Runtime-global Locks. (gh-112207)Sam Gross2023-12-07
| | | | | This replaces some usages of PyThread_type_lock with PyMutex, which does not require memory allocation to initialize. This simplifies some of the runtime initialization and is also one step towards avoiding changing the default raw memory allocator during initialize/finalization, which can be non-thread-safe in some circumstances.
* gh-111962: Make dtoa thread-safe in `--disable-gil` builds. (#112049)Sam Gross2023-12-07
| | | | | | | | | | | | | | | | | | | | This updates `dtoa.c` to avoid using the Bigint free-list in --disable-gil builds and to pre-computes the needed powers of 5 during interpreter initialization. * gh-111962: Make dtoa thread-safe in `--disable-gil` builds. This avoids using the Bigint free-list in `--disable-gil` builds and pre-computes the needed powers of 5 during interpreter initialization. * Fix size of cached powers of 5 array. We need the powers of 5 up to 5**512 because we only jump straight to underflow when the exponent is less than -512 (or larger than 308). * Rename Py_NOGIL to Py_GIL_DISABLED * Changes from review * Fix assertion placement
* gh-112567: Add _Py_GetTicksPerSecond() function (#112587)Victor Stinner2023-12-01
| | | | | | | | | | * Move _PyRuntimeState.time to _posixstate.ticks_per_second and time_module_state.ticks_per_second. * Add time_module_state.clocks_per_second. * Rename _PyTime_GetClockWithInfo() to py_clock(). * Rename _PyTime_GetProcessTimeWithInfo() to py_process_time(). * Add process_time_times() helper function, called by py_process_time(). * os.times() is now always built: no longer rely on HAVE_TIMES.
* gh-112367: Only free perf trampoline arenas at shutdown (#112368)Pablo Galindo Salgado2023-12-01
| | | Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-108082: Use PyErr_FormatUnraisable() (GH-111580)Serhiy Storchaka2023-11-02
| | | | | | Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-76785: Crossinterp utils additions (gh-111530)Eric Snow2023-11-01
| | | | | | | | | | | | This moves several general internal APIs out of _xxsubinterpretersmodule.c and into the new Python/crossinterp.c (and the corresponding internal headers). Specifically: * _Py_excinfo, etc.: the initial implementation for non-object exception snapshots (in pycore_pyerrors.h and Python/errors.c) * _PyXI_exception_info, etc.: helpers for passing an exception beween interpreters (wraps _Py_excinfo) * _PyXI_namespace, etc.: helpers for copying a dict of attrs between interpreters * _PyXI_Enter(), _PyXI_Exit(): functions that abstract out the transitions between one interpreter and a second that will do some work temporarily Again, these were all abstracted out of _xxsubinterpretersmodule.c as generalizations. I plan on proposing these as public API at some point.
* gh-111520: Integrate the Tier 2 interpreter in the Tier 1 interpreter (#111428)Guido van Rossum2023-11-01
| | | | | | | | | | | - There is no longer a separate Python/executor.c file. - Conventions in Python/bytecodes.c are slightly different -- don't use `goto error`, you must use `GOTO_ERROR(error)` (same for others like `unused_local_error`). - The `TIER_ONE` and `TIER_TWO` symbols are only valid in the generated (.c.h) files. - In Lib/test/support/__init__.py, `Py_C_RECURSION_LIMIT` is imported from `_testcapi`. - On Windows, in debug mode, stack allocation grows from 8MiB to 12MiB. - **Beware!** This changes the env vars to enable uops and their debugging to `PYTHON_UOPS` and `PYTHON_LLTRACE`.
* gh-110722: Add PYTHON_PRESITE to import a module before site.py is run (#110769)Łukasz Langa2023-10-14
|
* gh-109549: Add new states to PyThreadState to support PEP 703 (gh-109915)Sam Gross2023-10-05
| | | This adds a new field 'state' to PyThreadState that can take on one of three values: _Py_THREAD_ATTACHED, _Py_THREAD_DETACHED, or _Py_THREAD_GC. The "attached" and "detached" states correspond closely to acquiring and releasing the GIL. The "gc" state is current unused, but will be used to implement stop-the-world GC for --disable-gil builds in the near future.
* gh-109860: Use a New Thread State When Switching Interpreters, When ↵Eric Snow2023-10-03
| | | | | | | | | Necessary (gh-110245) In a few places we switch to another interpreter without knowing if it has a thread state associated with the current thread. For the main interpreter there wasn't much of a problem, but for subinterpreters we were *mostly* okay re-using the tstate created with the interpreter (located via PyInterpreterState_ThreadHead()). There was a good chance that tstate wasn't actually in use by another thread. However, there are no guarantees of that. Furthermore, re-using an already used tstate is currently fragile. To address this, now we create a new thread state in each of those places and use it. One consequence of this change is that PyInterpreterState_ThreadHead() may not return NULL (though that won't happen for the main interpreter).
* gh-109853: Fix sys.path[0] For Subinterpreters (gh-109994)Eric Snow2023-10-02
| | | This change makes sure sys.path[0] is set properly for subinterpreters. Before, it wasn't getting set at all. This PR does not address the broader concerns from gh-109853.
* gh-110014: Include explicitly <unistd.h> header (#110155)Victor Stinner2023-09-30
| | | | | | | | | | | * Remove unused <locale.h> includes. * Remove unused <fcntl.h> include in traceback.h. * Remove redundant <assert.h> and <stddef.h> includes. They are already included by "Python.h". * Remove <object.h> include in faulthandler.c. Python.h already includes it. * Add missing <stdbool.h> in pycore_pythread.h if HAVE_PTHREAD_STUBS is defined. * Fix also warnings in pthread_stubs.h: don't redefine macros if they are already defined, like the __NEED_pthread_t macro.
* gh-110079: Remove extern "C" { ...} in C code (#110080)Victor Stinner2023-09-29
|
* gh-109611: Add convenient C API function _PyFile_Flush() (GH-109612)Serhiy Storchaka2023-09-23
|
* GH-108716: Turn off deep-freezing of code objects. (GH-108722)Mark Shannon2023-09-08
|