2025-05-11 17:35:37 +08:00
|
|
|
import dataclasses
|
|
|
|
|
import multiprocessing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
|
class Config:
|
|
|
|
|
arg: int = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global_config = Config(arg=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process1():
|
2025-06-10 20:35:01 +08:00
|
|
|
print("Process1 arg=", global_config.arg)
|
2025-05-11 17:35:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
global_config.arg = 3
|
|
|
|
|
multiprocessing.set_start_method("spawn")
|
|
|
|
|
p1 = multiprocessing.Process(target=process1)
|
|
|
|
|
p1.start()
|
|
|
|
|
p1.join()
|
2025-06-10 20:35:01 +08:00
|
|
|
print("main arg=", global_config.arg)
|
2025-05-11 17:35:37 +08:00
|
|
|
|
|
|
|
|
|
2025-06-10 20:35:01 +08:00
|
|
|
if __name__ == "__main__":
|
2025-05-11 17:35:37 +08:00
|
|
|
main()
|