Load settings.ini in child process

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2022-11-18 13:32:29 +09:00
parent 1960e1c643
commit 0f1010baee
3 changed files with 11 additions and 14 deletions

View File

@@ -496,6 +496,5 @@ Settings = SettingsClass()
def setup_logging(env_key="LOG_CFG"): def setup_logging(env_key="LOG_CFG"):
config = os.getenv(env_key, None) config = os.getenv(env_key, None)
if config is not None and os.path.exists(config): if config is not None and os.path.exists(config):
logging.config.fileConfig(config) Settings.loggingconf = config
else: logging.config.fileConfig(Settings.loggingconf)
logging.config.fileConfig(Settings.loggingconf)

View File

@@ -1099,7 +1099,7 @@ def run_installer(archives: List[QtPackage], base_dir: str, sevenzip: Optional[s
# #
tasks = [] tasks = []
for arc in archives: for arc in archives:
tasks.append((arc, base_dir, sevenzip, queue, archive_dest, keep)) tasks.append((arc, base_dir, sevenzip, queue, archive_dest, Settings.configfile, keep))
ctx = multiprocessing.get_context("spawn") ctx = multiprocessing.get_context("spawn")
if is_64bit(): if is_64bit():
pool = ctx.Pool(Settings.concurrency, init_worker_sh, (), 4) pool = ctx.Pool(Settings.concurrency, init_worker_sh, (), 4)
@@ -1154,8 +1154,8 @@ def installer(
command: Optional[str], command: Optional[str],
queue: multiprocessing.Queue, queue: multiprocessing.Queue,
archive_dest: Path, archive_dest: Path,
keep: bool = False, settings_ini: str,
response_timeout: Optional[int] = None, keep: bool,
): ):
""" """
Installer function to download archive files and extract it. Installer function to download archive files and extract it.
@@ -1165,10 +1165,9 @@ def installer(
base_url = qt_package.base_url base_url = qt_package.base_url
archive: Path = archive_dest / qt_package.archive archive: Path = archive_dest / qt_package.archive
start_time = time.perf_counter() start_time = time.perf_counter()
# set defaults Settings.load_settings(file=settings_ini)
Settings.load_settings() # setup queue logger
# set logging setup_logging()
setup_logging() # XXX: why need to load again?
qh = QueueHandler(queue) qh = QueueHandler(queue)
logger = getLogger() logger = getLogger()
for handler in logger.handlers: for handler in logger.handlers:
@@ -1176,10 +1175,7 @@ def installer(
logger.removeHandler(handler) logger.removeHandler(handler)
logger.addHandler(qh) logger.addHandler(qh)
# #
if response_timeout is None: timeout = (Settings.connection_timeout, Settings.response_timeout)
timeout = (Settings.connection_timeout, Settings.response_timeout)
else:
timeout = (Settings.connection_timeout, response_timeout)
hash = get_hash(qt_package.archive_path, algorithm="sha256", timeout=timeout) hash = get_hash(qt_package.archive_path, algorithm="sha256", timeout=timeout)
def download_bin(_base_url): def download_bin(_base_url):

View File

@@ -1215,6 +1215,8 @@ def test_install_installer_archive_extraction_err(monkeypatch):
command="some_nonexistent_7z_extractor", command="some_nonexistent_7z_extractor",
queue=MockMultiprocessingManager.Queue(), queue=MockMultiprocessingManager.Queue(),
archive_dest=Path(temp_dir), archive_dest=Path(temp_dir),
settings_ini=Settings.configfile,
keep=False,
) )
assert err.type == ArchiveExtractionError assert err.type == ArchiveExtractionError
err_msg = format(err.value).rstrip() err_msg = format(err.value).rstrip()