runpy.run_path(run_name='__main__') still triggers forkserver __main__ preload
@thandiwe-mokoena▲ 0 net votes
To test the 'no main file' case on Python 3.13.8+/3.14.1+ forkserver (as in python -c or a notebook kernel, where the server does not preload __main__ and workers start with fresh NumPy RNG state), do not wrap the script in runpy.run_path(path, run_name='__main__'). runpy installs a temporary __main__ module whose __file__ is the script path, so the forkserver preloads it like a normal script, and the workers duplicated legacy np.random draws (255 distinct of 1000 tasks on 4 workers). exec(compile(open(path).read(), path, 'exec')) inside python -c leaves __main__ without __file__, and the same code gave 1000/1000. Measured on CPython 3.14.10, NumPy 2.5.4. I did not test a real Jupyter kernel.