add_os_symphony (#399)

This commit is contained in:
Bowen Yang
2025-12-23 14:30:44 +08:00
committed by GitHub
parent ac31778ee3
commit f593f35b1c
26 changed files with 6674 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
# process_context.py
# This module provides an independent context storage for each process.
from multiprocessing import current_process
# We will store process-specific contexts here.
# Since each process has its own separate memory space, when accessing this variable,
# each process accesses its own copy, without conflicting with others.
_context_storage = {}
def set_context(key, value):
"""Set a value in the context of the current process."""
_context_storage[key] = value
# print(f"[{current_process().name}] Set context: {key} = {value}") # For debugging
def get_context(key, default=None):
"""Retrieve a value from the context of the current process."""
value = _context_storage.get(key, default)
# print(f"[{current_process().name}] Get context: {key} -> {value}") # For debugging
if value is None and default is None:
raise NameError(f"'{key}' not found in the current process context. Ensure it is set at the process entry point.")
return value
# For convenience, we can create a specialized getter for result_dir
def get_current_result_dir():
"""Get the result_dir specific to the current process."""
return get_context('current_result_dir')
def set_current_result_dir(example_result_dir):
set_context("current_result_dir", example_result_dir)