| 1 |
# gh-143706: Test that sys.argv is correctly set during main module import |
| 2 |
# when using forkserver with __main__ preloading. |
| 3 |
|
| 4 |
import multiprocessing |
| 5 |
import sys |
| 6 |
|
| 7 |
# This will be printed during module import - sys.argv should be correct here |
| 8 |
print(f"module:{sys.argv[1:]}") |
| 9 |
|
| 10 |
def fun(): |
| 11 |
# This will be printed when the function is called |
| 12 |
print(f"fun:{sys.argv[1:]}") |
| 13 |
|
| 14 |
if __name__ == "__main__": |
| 15 |
ctx = multiprocessing.get_context("forkserver") |
| 16 |
ctx.set_forkserver_preload(['__main__']) |
| 17 |
|
| 18 |
fun() |
| 19 |
|
| 20 |
p = ctx.Process(target=fun) |
| 21 |
p.start() |
| 22 |
p.join() |