gh-135335: Simplify preload regression test using __main__ (GH-138686)

Simplify preload regression test using `__main__`

With the fix for gh-126631 `__main__` modules can be preloaded and the regression
test for gh-135335 can be simplified to just use a self-contained script rather
than requiring a module.

Note this assumes and implicitly tests that `__main__` is preloaded by default.
This commit is contained in:
Duane Griffin 2025-11-24 12:37:15 +13:00 committed by GitHub
parent 23b67aa037
commit 425f24e4fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 24 deletions

View file

@ -1,15 +1,11 @@
import multiprocessing
import sys
modname = 'preloaded_module'
print(__name__, end='', file=sys.stderr)
print(__name__, end='', file=sys.stdout)
if __name__ == '__main__':
if modname in sys.modules:
raise AssertionError(f'{modname!r} is not in sys.modules')
multiprocessing.set_start_method('forkserver')
multiprocessing.set_forkserver_preload([modname])
for _ in range(2):
p = multiprocessing.Process()
p.start()
p.join()
elif modname not in sys.modules:
raise AssertionError(f'{modname!r} is not in sys.modules')