Peter Bierma [Fri, 19 Sep 2025 12:17:05 +0000 (08:17 -0400)]
gh-126016: Remove bad assertion in `PyThreadState_Clear` (GH-139158)
In the _interpreters module, we use PyEval_EvalCode() to run Python code in another interpreter. However, when the process receives a KeyboardInterrupt, PyEval_EvalCode() will jump straight to finalization rather than returning. This prevents us from cleaning up and marking the thread as "not running main", which triggers an assertion in PyThreadState_Clear() on debug builds. Since everything else works as intended, remove that assertion.
gh-81148: Eliminate unnecessary check in _strptime when determining AM/PM (#13428)
* bpo-36967: Eliminate unnecessary check in _strptime when determining AM/PM
* Pauls suggestion to refactor test
* Fix test
---------
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
Peter Bierma [Thu, 18 Sep 2025 20:04:01 +0000 (16:04 -0400)]
gh-136003: Skip non-daemon threads when exceptions occur during finalization (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.
Peter Bierma [Thu, 18 Sep 2025 12:10:41 +0000 (08:10 -0400)]
Document `Py_AddPendingCall()` change with subinterpreters in 3.12 (GH-139117)
Prior to 3.9, Py_AddPendingCall() would always run pending calls in the main interpreter, but then each interpreter got their own ceval state, and they were scheduled for any interpreter. In GH-104813, this was undone, so Py_AddPendingCall() would always schedule for the main interpreter.
Peter Bierma [Thu, 18 Sep 2025 11:00:50 +0000 (07:00 -0400)]
gh-139098: Use multiphase initialization in `_testcapi` (GH-139102)
Use multiphase initialization in the _testcapi module to allow loading in subinterpreters. The isolation here isn't perfect as there's still some use of globals, but _testcapi should generally work in other interpreters.
Malcolm Smith [Thu, 18 Sep 2025 10:41:21 +0000 (11:41 +0100)]
Make Android streams respect the unbuffered (`-u`) option (#138806)
Android pipes stdout/stderr to the log, which means every write to the log
becomes a separate log line. As a result, most practical uses of stdout/stderr
should be buffered; but it doesn't hurt to preserve unbuffered handling in case
it's useful.
gh-138720: Make Buffered closed check match flush (GH-138724)
In `_io__Buffered_flush_impl` the macro `CHECK_CLOSED` is used to check
the `buffered*` is in a good state to be flushed. That differs slightly
from `buffered_closed`.
In some cases, that difference would result in `close()` thinking the
file needed to be flushed and closed while `flush()` thought the file
was already closed.
This could happen during GC and would result in an unraisable exception.
gh-138813: Fix mutable default kwargs={} in multiprocessing BaseProcess and DummyProcess to use None (GH-138814)
* gh-138813: Default `BaseProcess` `kwargs` to `None` (#138814)
Set `BaseProcess.__init__(..., kwargs=None)` and initialize `kwargs` with
`dict(kwargs) if kwargs else {}`. This avoids a shared mutable default and
matches threading.Thread behavior.
gh-128627: Use __builtin_wasm_test_function_pointer_signature for Emscripten trampoline (#137470)
With https://github.com/llvm/llvm-project/pull/150201 being merged, there is
now a better way to generate the Emscripten trampoline, instead of including
hand-generated binary WASM content. Requires Emscripten 4.0.12.
gh-137226: Fix get_type_hints() on generic TypedDict with stringified annotations (#138953)
This issue appears specifically for TypedDicts because the TypedDict constructor
code converts string annotations to ForwardRef objects, and those are not evaluated
properly by the get_type_hints() stack because of other shenanigans with type
parameters.
This issue does not affect normal generic classes because their annotations are not
pre-converted to ForwardRefs.
The fix attempts to restore the pre- #137227 behavior in the narrow scenario where
the issue manifests. It mostly makes changes only in the paths accessible from get_type_hints(),
ensuring that newer APIs (such as evaluate_forward_ref() and annotationlib) are not affected
by get_type_hints()'s past odd choices. This PR does not fix issue #138949, an older issue I
discovered while playing around with this one; we'll need a separate and perhaps more
invasive fix for that, but it should wait until after 3.14.0.
Benjamin Johnson [Tue, 16 Sep 2025 14:21:55 +0000 (08:21 -0600)]
gh-138514: getpass: restrict `echo_char` to a single ASCII character (#138591)
This amends commit bf8bbe9a813dd9fc2dd14be06df172b7d26ca1af by
restricting `echo_char` in `getpass.getpass` to single printable
ASCII characters as it would be uncommon to use long strings or
multi-byte characters for keyboard feedback.
Sam Gross [Tue, 16 Sep 2025 08:21:58 +0000 (09:21 +0100)]
gh-137433: Fix deadlock with stop-the-world and daemon threads (gh-137735)
There was a deadlock originally seen by Memray when a daemon thread
enabled or disabled profiling while the interpreter was shutting down.
I think this could also happen with garbage collection, but I haven't
seen that in practice.
The daemon thread could be hung while trying acquire the global rwmutex
that prevents overlapping global and per-interpreter stop-the-world events.
Since it already held the main interpreter's stop-the-world lock, it
also deadlocked the main thread, which is trying to perform interpreter
finalization.
Swap the order of lock acquisition to prevent this deadlock.
Additionally, refactor `_PyParkingLot_Park` so that the global buckets
hashtable is left in a clean state if the thread is hung in
`PyEval_AcquireThread`.
Mehdi Hassan [Mon, 15 Sep 2025 18:50:46 +0000 (19:50 +0100)]
gh-97517: Add documentation links to datetime strftime/strptime docstrings (#138559)
* Add documentation links to datetime strftime/strptime docstrings
- Add links to format codes documentation for all strftime methods
- Add links to format codes documentation for all strptime methods
- Addresses issue #97517
* Update C extension docstrings with format codes documentation
* Regenerate clinic code for updated docstrings
* Add clinic-generated header file for updated docstrings
* Fix docstring spacing consistency in both Python and C files
* Update Lib/_pydatetime.py
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
---------
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>