Fix incorrect sharing of current task with the forked child process by clearing thread state's current task and current loop in `PyOS_AfterFork_Child`.
Functions that take timestamp or timeout arguments now accept any
real numbers (such as Decimal and Fraction), not only integers or floats,
although this does not improve precision.
The following types are now immutable:
* `_curses_panel.panel`,
* `[posix,nt].ScandirIterator`, `[posix,nt].DirEntry` (exposed in `os.py`),
* `_remote_debugging.RemoteUnwinder`,
* `_tkinter.Tcl_Obj`, `_tkinter.tkapp`, `_tkinter.tktimertoken`,
* `zlib.Compress`, and `zlib.Decompress`.
While file timestamps can be anything the file system can store, most
lie between the recent past and the near future. Optimize fill_time()
for typical timestamps in three ways:
- When possible, convert to nanoseconds with C arithmetic.
- When using C arithmetic and the seconds member is not required (for
st_birthtime), avoid creating a long object.
- When using C arithmetic, reorder the code to avoid the null checks
implied in Py_XDECREF().
Co-authored-by: Victor Stinner <vstinner@python.org>
Don't ignore errors raised by `PyErr_WarnFormat` in `warn_about_fork_with_threads`
Instead, ignore the warnings in all test code that forks. (That's a lot of functions.)
In `test_support`, make `ignore_warnings` a context manager (as well as decorator),
and add a `message` argument to it.
Also add a `ignore_fork_in_thread_deprecation_warnings` helper for the deadlock-in-fork
warning.
Basic support for pyrepl in Emscripten. Limitations:
* requires JSPI
* no signal handling implemented
As followup work, it would be nice to implement a webworker variant
for when JSPI is not available and proper signal handling.
Because it requires JSPI, it doesn't work in Safari. Firefox requires
setting an experimental flag. All the Chromiums have full support since
May. Until we make it work without JSPI, let's keep the original web_example
around.
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Éric <merwok@netwok.org>
Clang-cl detects that on 32-bit builds the variable is always smaller than the value. But since the same code is used for other architectures, we can't just _fix_ it. This cast avoids the tautological-constant-out-of-range-compare warning.
This fixes os.link() on platforms (like Linux and OpenIndiana) where the
system link() function does not follow symlinks.
* On Linux, it now follows symlinks by default and if
follow_symlinks=True is specified.
* On Windows, it now raises error if follow_symlinks=True is passed.
* On macOS, it now raises error if follow_symlinks=False is passed and
the system linkat() function is not available at runtime.
* On other platforms, it now raises error if follow_symlinks is passed
with a value that does not match the system link() function behavior
if if the behavior is not known.
Co-authored-by: Joachim Henke <37883863+jo-he@users.noreply.github.com>
Co-authored-by: Thomas Kluyver <takowl@gmail.com>
Support it for the dev_t values in mknod(), major(), minor() and makedev(),
CPU numbers in sched_setaffinity(), group numbers in setgroups(),
configuration name in fpathconf(), pathconf(), confstr(), and sysconf().
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()`.
Add a new OS API which will read data directly into a caller provided
writeable buffer protocol object.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>