Fix Emscripten/WASI pattern in case statement for LDSHARED
(cherry picked from commit 47816f465e)
Co-authored-by: Michael Allwright <contact@allwright.io>
gh-119577: Adjust DeprecationWarning when testing element truth values in ElementTree (GH-119762)
Adjust DeprecationWarning when testing element truth values in ElementTree, we're planning to go with the more natural True return rather than a disruptive harder to code around exception raise, and are deferring the behavior change for a few more releases.
(cherry picked from commit 6b606522ca)
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
This adds a `_PyRecursiveMutex` type based on `PyMutex` and uses that
for the import lock. This fixes some data races in the free-threaded
build and generally simplifies the import lock code.
(cherry picked from commit e21057b999)
Co-authored-by: Sam Gross <colesbury@gmail.com>
The modified context caused tests failures in several other tests.
(cherry picked from commit 2d7ff6e0e7)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit fd104dfcb8)
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This matches the default GIL switch interval. It greatly speeds up the
free-threaded build: previously, it spent nearly all its time in
`gc.collect()`.
(cherry picked from commit 4bba1c9e6c)
Co-authored-by: Sam Gross <colesbury@gmail.com>
gh-119287: clarify doc on BaseExceptionGroup.derive and link to it from contextlib.suppress (GH-119657)
(cherry picked from commit 5c02ea8bae)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
The `test_imaplib` was taking 40+ minutes in the refleak build bots because
the tests waiting on a client `self._setup()` was creating a client that
prevented progress until its connection timed out, which scaled with the
global timeout.
We should set `connect=False` for the tests that don't want `_setup()` to
create a client.
(cherry picked from commit 710cbea660)
Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
We need to write to `ob_ref_local` and `ob_tid` before `ob_ref_shared`.
Once we mark `ob_ref_shared` as merged, some other thread may free the
object because the caller also passes in `-1` as `extra` to give up its
only reference.
(cherry picked from commit 4055577221)
Co-authored-by: Sam Gross <colesbury@gmail.com>
(cherry picked from commit d9095194dd)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
The process is expected to time out. In the refleak builds,
`support.SHORT_TIMEOUT` is often five minutes and we run the tests six
times, so test_signal was taking >30 minutes.
(cherry picked from commit d419d468ff)
Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-120041: Do not use append_to_screen when completions are visible (GH-120042)
(cherry picked from commit 8fc7653766)
* gh-120041: Refactor check for visible completion menu in completing_reader (GH-120055)
(cherry picked from commit bf8e5e53d0)
---------
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
(cherry picked from commit 7111d9605f)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
gh-119588: Update docs to reflect decision to include the change with Python 3.13 and not 3.12. (GH-120043)
(cherry picked from commit 4dcd91ceaf)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
gh-106531: Apply changes from importlib_resources 6.3.2 (GH-117054)
Apply changes from importlib_resources 6.3.2.
(cherry picked from commit 8d63c8d47b)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
The `_PyThreadState_Bind()` function is called before the first
`PyEval_AcquireThread()` so it's not synchronized with the stop the
world GC. We had a race where `gc_visit_heaps()` might visit a thread's
heap while it's being initialized.
Use a simple atomic int to avoid visiting heaps for threads that are not
yet fully initialized (i.e., before `tstate_mimalloc_bind()` is called).
The race was reproducible by running:
`python Lib/test/test_importlib/partial/pool_in_threads.py`.
(cherry picked from commit e69d068ad0)
Co-authored-by: Sam Gross <colesbury@gmail.com>
gh-119070: Update test_shebang_executable_extension to always use non-installed version (GH-119846)
(cherry picked from commit 5c48eb0cc6)
Co-authored-by: Steve Dower <steve.dower@python.org>
gh-111499: Fix PYTHONMALLOCSTATS at Python exit (GH-120021)
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before
the interpreter is deleted.
(cherry picked from commit 5a1205b641)
Co-authored-by: Victor Stinner <vstinner@python.org>
We make use of the same mechanism that we use for the static builtin types. This required a few tweaks.
This change is the final piece needed to make _datetime support multiple interpreters. I've updated the module slot accordingly.
(cherry picked from commit 105f22ea46, AKA gh-119929)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This makes the support official.
(cherry picked from commit dba7a167db, AKA gh-119991)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
I was able to make use of the existing datetime_state struct, but there was one tricky thing I had to sort out. We mostly aren't converting to heap types, so we can't use things like PyType_GetModuleByDef() to look up the module state. The solution I came up with is somewhat novel, but I consider it straightforward. Also, it shouldn't have much impact on performance.
In summary, this main changes here are:
* I've added some macros to help hide how various objects relate to module state
* as a solution to the module state lookup problem, I've stored the last loaded module on the current interpreter's internal dict (actually a weakref)
* if the static type method is used after the module has been deleted, it is reloaded
* to avoid extra work when loading the module, we directly copy the objects (new refs only) from the old module state into the new state if the old module hasn't been deleted yet
* during module init we set various objects on the static types' __dict__s; to simplify things, we only do that the first time; once those static types have a separate __dict__ per interpreter, we'll do it every time
* we now clear the module state when the module is destroyed (before, we were leaking everything in _datetime_global_state)
(cherry picked from commit d82a7ba041, AKA gh-119810)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.
This fixes a race condition involving the tracking of whether the
behavior is suppressed.
(cherry picked from commit 47fb4327b5)
The `sem_clockwait` function is not currently instrumented, which leads
to false positives.
(cherry picked from commit 41c1cefbae)
Co-authored-by: Sam Gross <colesbury@gmail.com>
gh-119336: Restore removed _PyLong_NumBits() function (GH-119418)
It is used by the pywin32 project.
(cherry picked from commit e50fac96e8)
Co-authored-by: Ethan Smith <ethan@ethanhs.me>
gh-119856: Support exiting help() with just "exit" (GH-119858)
(cherry picked from commit 4223f1d828)
Co-authored-by: Victor Stinner <vstinner@python.org>