Repository navigation
Conversation
…rt method Stop forcing the fork start method for the RPC and message servers and the t.rast.mapcalc and t.rast.extract workers. Use the platform default (spawn on Windows and macOS, forkserver on Linux since Python 3.14) and pass the session environment to the worker explicitly, because a forkserver worker otherwise gets the environment from the time the fork server started. Run the server start-method test with every available start method instead of skipping it, drop the spawn xfail of the GridModule tests by using a picklable function, and test that workers see the current environment. Written with the help of an AI assistant; the logic was reviewed and tested with the spawn and forkserver start methods on Linux and with Python 3.13 and 3.15.
Create the worker processes, locks, pipes and queues from a context which uses the current default start method without setting it, so applications can still choose a start method after using grass.pygrass or grass.temporal. Also start the MultiModule processes with the session environment, which is needed with the forkserver start method after the session changed. Skip the fork start method on macOS in the start-method test. Written with the help of an AI assistant; tested with Python 3.13 and 3.15.
Annotate the helpers for starting worker processes and the tests changed with them. Declare the type of RPCServerBase.server. Count a missing exit code as zero in t.rast.mapcalc and t.rast.extract, because the exit code of a process is optional. Written with the help of an AI assistant; checked with mypy, ty, pyrefly and zuban, which report no new problems and fewer than before.
Check the process returned by MultiModule.run() against BaseProcess, because the processes of a multiprocessing context are not instances of multiprocessing.Process. Check the exit code of the process in the GridModule tests, since failures of the module were not reported. Exclude fork on macOS from the start methods of the environment test. Written with the help of an AI assistant; tested with Python 3.13 and 3.15.
…text Scripts which use grass.temporal or the grass.pygrass servers need to run their code under a main guard with the spawn and forkserver start methods, which is now also needed on Linux with Python 3.14 and later. Describe it in the temporal framework documentation and add the guard to its examples. Let _environ_process() take the context, so that the process, the locks, the pipes and the queues use the same one even when the application changes the start method in between. Written with the help of an AI assistant; tested with Python 3.11, 3.13 and 3.15.
Without the main guard, Messenger does not raise an error, its messages are just not printed, so the note did not cover all failures. Also call Messenger and DataProvider classes, not tools, which in GRASS are the r.*, v.*, etc. commands. Written with the help of an AI assistant; tested by running scripts without the main guard using tgis.init(), Messenger, and DataProvider with Python 3.15 on Linux and by building the page with Sphinx.
…hod test A message server which fails to start loses the messages without an error, so the test passed even if the messages were not printed. Written with the help of an AI assistant; tested with pytest on Python 3.11, 3.13, and 3.15 and checked that the test fails when no message is sent.
The argument is already a Path, so wrapping it again is not needed and Path is only used for type annotations. Written with the help of an AI assistant; tested with pytest on Python 3.11 and 3.15.
|
Good news, it fixed 23+10 xfails on Windows, Before and after
Details
Status: the "before" run is main (15:39) and the "after" run is the PR merge ref (19:04). On Windows, 33 xfailed grid tests now pass. I'm still comparing the macOS, Ubuntu and gunittest reports. Short version: the PR does what it appears to be meant to do. It makes the Windows and macOS pygrass grid tests run instead of being marked xfail. I found no regression. The same Windows failures show up before and after, and they come from main. I took the older runs (15:29 to 15:39, Before and after
Things to be aware of
|
…a failure Summing the exit codes let a negative code (a tool killed by a signal) cancel out a positive one, so the failure went unnoticed.
The fake tools create no maps, so a later step fails too and the SystemExit alone does not show that the exit codes were handled.
So Claude complains that it passes sort of by accident:
|
I don't see why there's something different about workflows, that PR doesn't touch it. I ré-merged main into it in case there were other commits of main shown here. Otherwise, could you tell me what you meant |
…rkers With --import-mode=importlib, pytest imports test modules by their path relative to the root directory without adding the root to sys.path. The worker processes then could not import the test module to get the target function, unless the current directory happened to be the root and was on sys.path, as with the trailing colon in PYTHONPATH in CI.
8653af5 to
1756438
Compare
Description
The RPC and message servers (
grass.pygrass,grass.temporal) and thet.rast.mapcalcandt.rast.extractworkers no longer force theforkstart method. They use the platform default (spawn on Windows and macOS, forkserver on Linux since Python 3.14) through a context that does not fix the application's default start method. This removes the temporary workaround from #7724.A new
_environ_process()ingrass.script.utilspasses the session environment to the worker explicitly, because a forkserver worker otherwise gets the environment from when the fork server started. It takes the context, so the process, locks, pipes and queues always use the same one.MultiModuleuses it too.Tests:
forkis skipped on macOS).GridModuletests no longerxfailwith spawn, since they use a picklable function, and they check the exit code of the child process.Docs: the temporal framework documentation explains the
if __name__ == "__main__":guard and the examples use it.The new helpers and the tests changed with them have type annotations, checked with mypy, ty, pyrefly and zuban: no new diagnostics, and fewer than before.
Motivation and context
Python 3.14 made forkserver the default start method on Linux. #7724 ("grass.pygrass: Pin fork start method for RPC servers on Python 3.14") worked around the failure of the servers by pinning fork where it was the previous default, using a helper
_get_multiprocessing_context()ingrass.script.utilswhich is documented as a workaround until GRASS supports the spawn and forkserver start methods. This PR is that support: the servers and workers work with all start methods, so the pin is not needed anymore and the helper is replaced by one that does not force a method.Python 3.12+ also warns when
fork()is used in a multi-threaded process, as seen in the Python 3.13 CI logs (xdist workers and the RPC checker threads are multi-threaded). The fork warnings on 3.12 and 3.13 Linux remain, since fork is still the default there.Known limits:
if __name__ == "__main__":fail, because the main module is re-imported in the worker. This was already so on Windows and macOS and is now also so on Linux with Python 3.14 and later.grass.temporal, so thet.rast.mapcalcandt.rast.extractworkers start slower.GridModuleandt.rast.univarpool workers keep the fork server's environment, apart from GISRC, after a session switch.How has this been tested?
On Linux, with Python 3.11.15, 3.13.18 and 3.15.2 (default start method forkserver), in
grass.script,grass.temporal,grass.pygrassrpc, messages and modules tests: all pass (429 passed, 1 xfailed). The jupyter tests pass except 3reprojection_renderer_testtests, which needcs2cs(not installed). TheMultiModuledoctests pass with gunittest on 3.13 and 3.15. The same tests also pass with the default start method forced to spawn and to forkserver.pygrassMultiModule,t.rast.univar,t.rast.mapcalc,t.rast.extract, jupyterSeriesMap/TimeSeriesMapandi.colors.enhancewere run with all three start methods.prekpasses on the changed files. Not run on Windows, macOS or the wxPython GUI.Types of changes
functionality to not work as before)
Checklist
pre-defined prefixes
of this project.
Suggested squash commit message
Written with the help of an AI assistant (Claude); the changes were reviewed and tested as described above.