summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_embed.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-126925: Modify how iOS test results are gathered (#127592)Russell Keith-Magee2024-12-091-0/+2
| | | | | | | 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-126985: move pyvenv.cfg detection from site to getpath (#126987)Filipe Laíns 🇵🇸2024-11-261-2/+2
|
* gh-115999: Implement thread-local bytecode and enable specialization for ↵mpage2024-11-041-0/+1
| | | | | | | | | `BINARY_OP` (#123926) Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads. Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization. Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.
* gh-126255: Ignore warning about JIT being deactivated when perf support is ↵mpage2024-11-011-1/+4
| | | | | | | | | | | 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-125837: Split `LOAD_CONST` into three. (GH-125972)Mark Shannon2024-10-291-0/+3
| | | | | | | | * Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
* bpo-34206: Improve docs and test coverage for pre-init functions (#8023)Alyssa Coghlan2024-10-081-1/+10
| | | | | | | | | | | | | | | | | | | | - move the Py_Main documentation from the very high level API section to the initialization and finalization section - make it clear that it encapsulates a full Py_Initialize/Finalize cycle of its own - point out that exactly which settings will be read and applied correctly when Py_Main is called after a separate runtime initialization call is version dependent - be explicit that Py_IsInitialized can be called prior to initialization - actually test that Py_IsInitialized can be called prior to initialization - flush stdout in the embedding tests that run code so it appears in the expected order when running with "-vv" - make "-vv" on the subinterpreter embedding tests less spammy --------- Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
* gh-107954: Fix configuration type for the perf profiler (#124636)Pablo Galindo Salgado2024-09-271-5/+8
|
* gh-108303: Remove the non-test `Lib/test/reperf.py` (GH-114356)sobolevn2024-09-131-4/+7
|
* gh-117482: Simplify the Fix For Builtin Types Slot Wrappers (GH-122865)Eric Snow2024-09-091-1/+0
| | | | | | | | | | | | | | | | | In gh-121602, I applied a fix to a builtin types initialization bug. That fix made sense in the context of some broader future changes, but introduced a little bit of extra complexity. That fix has turned out to be incomplete for some of the builtin types we haven't been testing. I found that out while improving the tests. A while back, @markshannon suggested a simpler fix that doesn't have that problem, which I've already applied to 3.12 and 3.13. I'm switching to that here. Given the potential long-term benefits of the more complex (but still incomplete) approach, I'll circle back to it in the future, particularly after I've improved the tests so no corner cases slip through the cracks. (This is effectively a "forward-port" of 716c677 from 3.13.)
* gh-107954, PEP 741: Add PyInitConfig_AddModule() function (#123668)Victor Stinner2024-09-041-0/+3
|
* gh-107954, PEP 741: Adjust Python initialization config (#123663)Victor Stinner2024-09-041-1/+0
| | | | | | | Setting dev_mode to 1 in an isolated configuration now enables also faulthandler. Moreover, setting "module_search_paths" option with PyInitConfig_SetStrList() now sets "module_search_paths_set" to 1.
* gh-107954, PEP 741: Add PyInitConfig C API (#123502)Victor Stinner2024-09-031-10/+36
| | | Add Doc/c-api/config.rst documentation.
* gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472)Victor Stinner2024-09-021-50/+54
| | | | | | | | | | | Add PyConfig_Get(), PyConfig_GetInt(), PyConfig_Set() and PyConfig_Names() functions to get and set the current runtime Python configuration. Add visibility and "sys spec" to config and preconfig specifications. _PyConfig_AsDict() now converts PyConfig.xoptions as a dictionary. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-123022: Fix crash with `Py_Initialize` in background thread (#123052)Sam Gross2024-08-171-1/+8
| | | | | | | | | | | | Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build.
* gh-117482: Make the Slot Wrapper Inheritance Tests Much More Thorough ↵Eric Snow2024-08-121-24/+33
| | | | | | | | | | (gh-122867) There were a still a number of gaps in the tests, including not looking at all the builtin types and not checking wrappers in subinterpreters that weren't in the main interpreter. This fixes all that. I considered incorporating the names of the PyTypeObject fields (a la gh-122866), but figured doing so doesn't add much value.
* gh-122334: Fix test_embed failure when missing _ssl module (GH-122630)neonene2024-08-031-2/+6
| | | Co-authored-by: Wulian233 <1055917385@qq.com>
* gh-122334: Fix crash when importing ssl after re-initialization (#122481)neonene2024-08-021-0/+19
| | | | * Fix crash when importing ssl after re-initialization
* gh-117482: Fix the Slot Wrapper Inheritance Tests (gh-122248)Eric Snow2024-07-291-19/+38
| | | The tests were only checking cases where the slot wrapper was present in the initial case. They were missing when the slot wrapper was added in the additional initializations. This fixes that.
* gh-117482: Expand Tests for Slot Wrappers of Inherited Slots of Static ↵Eric Snow2024-07-231-0/+27
| | | | Builtin Types (gh-122192)
* gh-121103: Put free-threaded libraries in `lib/python3.14t` (#121293)Sam Gross2024-07-111-6/+8
| | | | | On POSIX systems, excluding macOS framework installs, the lib directory for the free-threaded build now includes a "t" suffix to avoid conflicts with a co-located default build installation.
* gh-71587: Drop local reference cache to `_strptime` module in `_datetime` ↵neonene2024-06-121-0/+9
| | | | | (gh-120224) The _strptime module object was cached in a static local variable (in the datetime.strptime() implementation). That's a problem when it crosses isolation boundaries, such as reinitializing the runtme or between interpreters. This change fixes the problem by dropping the static variable, instead always relying on the normal sys.modules cache (via PyImport_Import()).
* gh-117786: Fix venv created from Windows Store install by restoring ↵Steve Dower2024-04-241-0/+3
| | | | __PYVENV_LAUNCHER__ smuggling (GH-117814)
* gh-116303: Skip test module dependent tests if test modules are unavailable ↵Erlend E. Aasland2024-04-031-1/+11
| | | | (#117341)
* gh-116167: Allow disabling the GIL with `PYTHON_GIL=0` or `-X gil=0` (#116338)Brett Simmers2024-03-111-0/+2
| | | | | | | | | In free-threaded builds, running with `PYTHON_GIL=0` will now disable the GIL. Follow-up issues track work to re-enable the GIL when loading an incompatible extension, and to disable the GIL by default. In order to support re-enabling the GIL at runtime, all GIL-related data structures are initialized as usual, and disabling the GIL simply sets a flag that causes `take_gil()` and `drop_gil()` to return early.
* gh-107954: Add PyConfig_MEMBER_BOOL type to PyConfigSpec (#116359)Victor Stinner2024-03-061-114/+114
| | | | | | _PyConfig_AsDict() now returns bool objects for options using the new PyConfig_MEMBER_BOOL type. Update tests for these changes.
* gh-112532: Require mimalloc in `--disable-gil` builds (gh-112883)Sam Gross2023-12-121-4/+10
|
* gh-110722: Add PYTHON_PRESITE to import a module before site.py is run (#110769)Łukasz Langa2023-10-141-0/+18
|
* gh-109595: Add -Xcpu_count=<n> cmdline for container users (#109667)Donghee Na2023-10-101-0/+2
| | | | | | --------- Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
* Add support.MS_WINDOWS constant (#110446)Victor Stinner2023-10-061-5/+2
|
* gh-85283: Add PySys_AuditTuple() function (#108965)Victor Stinner2023-10-051-0/+3
| | | | | | sys.audit() now has assertions to check that the event argument is not NULL and that the format argument does not use the "N" format. Add tests on PySys_AuditTuple().
* gh-109853: Fix sys.path[0] For Subinterpreters (gh-109994)Eric Snow2023-10-021-0/+3
| | | 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-107954: Refactor initconfig.c: add CONFIG_SPEC (#110146)Victor Stinner2023-09-301-0/+1
| | | Add a specification of the PyConfig structure to factorize the code.
* gh-108753: Enhance pystats (#108754)Victor Stinner2023-09-061-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Statistics gathering is now off by default. Use the "-X pystats" command line option or set the new PYTHONSTATS environment variable to 1 to turn statistics gathering on at Python startup. Statistics are no longer dumped at exit if statistics gathering was off or statistics have been cleared. Changes: * Add PYTHONSTATS environment variable. * sys._stats_dump() now returns False if statistics are not dumped because they are all equal to zero. * Add PyConfig._pystats member. * Add tests on sys functions and on setting PyConfig._pystats to 1. * Add Include/cpython/pystats.h and Include/internal/pycore_pystats.h header files. * Rename '_py_stats' variable to '_Py_stats'. * Exclude Include/cpython/pystats.h from the Py_LIMITED_API. * Move pystats.h include from object.h to Python.h. * Add _Py_StatsOn() and _Py_StatsOff() functions. Remove '_py_stats_struct' variable from the API: make it static in specialize.c. * Document API in Include/pystats.h and Include/cpython/pystats.h. * Complete pystats documentation in Doc/using/configure.rst. * Don't write "all zeros" stats: if _stats_off() and _stats_clear() or _stats_dump() were called. * _PyEval_Fini() now always call _Py_PrintSpecializationStats() which does nothing if stats are all zeros. Co-authored-by: Michael Droettboom <mdboom@gmail.com>
* gh-105481: generate op IDs from bytecode.c instead of hard coding them in ↵Irit Katriel2023-08-161-1/+1
| | | | opcode.py (#107971)
* gh-99113: Add PyInterpreterConfig.own_gil (gh-104204)Eric Snow2023-05-051-0/+1
| | | | | We also add PyInterpreterState.ceval.own_gil to record if the interpreter actually has its own GIL. Note that for now we don't actually respect own_gil; all interpreters still share the one GIL. However, PyInterpreterState.ceval.own_gil does reflect PyInterpreterConfig.own_gil. That lie is a temporary one that we will fix when the GIL really becomes per-interpreter.
* GH-103805: Lib test f541 linting issue fix (#103812)Rodolfo M. Pereira2023-04-241-1/+1
| | | | | | | | | | | | | | | | This PR makes some minor linting adjustments to the Lib/test module caught by [ruff](https://github.com/charliermarsh/ruff). The adjustments are all related to the `F541 f-string without any placeholders` issue. Issue: https://github.com/python/cpython/issues/103805 <!-- gh-issue-number: gh-103805 --> * Issue: gh-103805 <!-- /gh-issue-number --> --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-101659: Isolate "obmalloc" State to Each Interpreter (gh-101660)Eric Snow2023-04-241-1/+2
| | | | | | | | | | | | | | This is strictly about moving the "obmalloc" runtime state from `_PyRuntimeState` to `PyInterpreterState`. Doing so improves isolation between interpreters, specifically most of the memory (incl. objects) allocated for each interpreter's use. This is important for a per-interpreter GIL, but such isolation is valuable even without it. FWIW, a per-interpreter obmalloc is the proverbial canary-in-the-coalmine when it comes to the isolation of objects between interpreters. Any object that leaks (unintentionally) to another interpreter is highly likely to cause a crash (on debug builds at least). That's a useful thing to know, relative to interpreter isolation.
* gh-98627: Add an Optional Check for Extension Module Subinterpreter ↵Eric Snow2023-02-161-1/+3
| | | | | | | | | | | | | | | Compatibility (gh-99040) Enforcing (optionally) the restriction set by PEP 489 makes sense. Furthermore, this sets the stage for a potential restriction related to a per-interpreter GIL. This change includes the following: * add tests for extension module subinterpreter compatibility * add _PyInterpreterConfig.check_multi_interp_extensions * add Py_RTFLAGS_MULTI_INTERP_EXTENSIONS * add _PyImport_CheckSubinterpIncompatibleExtensionAllowed() * fail iff the module does not implement multi-phase init and the current interpreter is configured to check https://github.com/python/cpython/issues/98627
* gh-100712: make it possible to disable specialization (for debugging) (#100713)Irit Katriel2023-01-191-0/+2
|
* gh-100320: Fix path calculations on Windows when python.exe is moved outside ↵Steve Dower2023-01-161-7/+9
| | | | of the normal location (GH-100947)
* GH-98686: Get rid of "adaptive" and "quick" instructions (GH-99182)Brandt Bucher2022-11-091-4/+0
|
* gh-98790: When DLLs directory is missing on Windows, assume executable_dir ↵Steve Dower2022-11-021-13/+7
| | | | contains PYD files instead (GH-98936)
* GH-98686: Quicken everything (GH-98687)Brandt Bucher2022-11-021-19/+27
|
* gh-98610: Adjust the Optional Restrictions on Subinterpreters (GH-98618)Eric Snow2022-10-311-2/+3
| | | | | | | Previously, the optional restrictions on subinterpreters were: disallow fork, subprocess, and threads. By default, we were disallowing all three for "isolated" interpreters. We always allowed all three for the main interpreter and those created through the legacy `Py_NewInterpreter()` API. Those settings were a bit conservative, so here we've adjusted the optional restrictions to: fork, exec, threads, and daemon threads. The default for "isolated" interpreters disables fork, exec, and daemon threads. Regular threads are allowed by default. We continue always allowing everything For the main interpreter and the legacy API. In the code, we add `_PyInterpreterConfig.allow_exec` and `_PyInterpreterConfig.allow_daemon_threads`. We also add `Py_RTFLAGS_DAEMON_THREADS` and `Py_RTFLAGS_EXEC`.
* gh-96853: Restore test coverage for Py_Initialize(Ex) (GH-98212)Nick Coghlan2022-10-301-0/+6
| | | | | | | | | | | * As most of `test_embed` now uses `Py_InitializeFromConfig`, add a specific test case to cover `Py_Initialize` (and `Py_InitializeEx`) * Rename `_testembed` init helper to clarify the API used * Add a `PyConfig_Clear` call in `Py_InitializeEx` to make the code more obviously correct (it already didn't leak as none of the dynamically allocated config fields were being populated, but it's clearer if the wrappers follow the documented API usage guidelines)
* gh-98608: Change _Py_NewInterpreter() to _Py_NewInterpreterFromConfig() ↵Eric Snow2022-10-261-3/+19
| | | | | | | | | | | | | | | | | | | | | | | | | (gh-98609) (see https://github.com/python/cpython/issues/98608) This change does the following: 1. change the argument to a new `_PyInterpreterConfig` struct 2. rename the function to `_Py_NewInterpreterFromConfig()`, inspired by `Py_InitializeFromConfig()` (takes a `_PyInterpreterConfig` instead of `isolated_subinterpreter`) 3. split up the boolean `isolated_subinterpreter` into the corresponding multiple granular settings * allow_fork * allow_subprocess * allow_threads 4. add `PyInterpreterState.feature_flags` to store those settings 5. add a function for checking if a feature is enabled on an opaque `PyInterpreterState *` 6. drop `PyConfig._isolated_interpreter` The existing default (see `Py_NewInterpeter()` and `Py_Initialize*()`) allows fork, subprocess, and threads and the optional "isolated" interpreter (see the `_xxsubinterpreters` module) disables all three. None of that changes here; the defaults are preserved. Note that the given `_PyInterpreterConfig` will not be used outside `_Py_NewInterpreterFromConfig()`, nor preserved. This contrasts with how `PyConfig` is currently preserved, used, and even modified outside `Py_InitializeFromConfig()`. I'd rather just avoid that mess from the start for `_PyInterpreterConfig`. We can preserve it later if we find an actual need. This change allows us to follow up with a number of improvements (e.g. stop disallowing subprocess and support disallowing exec instead). (Note that this PR adds "private" symbols. We'll probably make them public, and add docs, in a separate change.)
* gh-96512: Move int_max_str_digits setting to PyConfig (#96944)Gregory P. Smith2022-10-031-0/+4
| | | | | | | | | | | It had to live as a global outside of PyConfig for stable ABI reasons in the pre-3.12 backports. This removes the `_Py_global_config_int_max_str_digits` and gets rid of the equivalent field in the internal `struct _is PyInterpreterState` as code can just use the existing nested config struct within that. Adds tests to verify unique settings and configs in subinterpreters.
* GH-96975: Skip incomplete frames in PyEval_GetFrame (GH-97003)Brandt Bucher2022-09-221-0/+3
|
* gh-96143: Allow Linux perf profiler to see Python calls (GH-96123)Pablo Galindo Salgado2022-08-301-0/+5
| | | | | | | :warning: :warning: Note for reviewers, hackers and fellow systems/low-level/compiler engineers :warning: :warning: If you have a lot of experience with this kind of shenanigans and want to improve the **first** version, **please make a PR against my branch** or **reach out by email** or **suggest code changes directly on GitHub**. If you have any **refinements or optimizations** please, wait until the first version is merged before starting hacking or proposing those so we can keep this PR productive.
* bpo-45445: Revert "bpo-45445: Fail if an invalid X-option is provided in the ↵Pablo Galindo Salgado2022-07-311-12/+11
| | | | command line (GH-28823)" (#94745)