Skip to content

Commit

Permalink
set logger to be multiprocessing-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
monodera committed Oct 1, 2024
1 parent f13ff7c commit 505b308
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/pfs_target_uploader/pn_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import os
import sys
from datetime import datetime, timezone

import gurobipy
Expand Down Expand Up @@ -38,11 +39,17 @@ def _toggle_widgets(widgets: list, disabled: bool = True):
def target_uploader_app(use_panel_cli=False):
pn.state.notifications.position = "bottom-left"

config = dotenv_values(".env.shared")

# configure logger to be multiprocessing-safe
log_level = config["LOG_LEVEL"] if "LOG_LEVEL" in config.keys() else "INFO"
logger.info(f"Log level is set to {log_level}")
logger.remove()
logger.add(sys.stderr, level=log_level, enqueue=True)

logger.info(f"{pn.state.headers=}")
logger.info(f"{pn.state.location.href=}")

config = dotenv_values(".env.shared")

if "MAX_EXETIME" not in config.keys():
max_exetime: int = 900
else:
Expand Down Expand Up @@ -434,6 +441,7 @@ def cb_PPP(event):
clustering_algorithm=clustering_algorithm,
quiet=ppp_quiet,
max_exetime=max_exetime,
logger=logger,
)

panel_ppp.show_results()
Expand Down
5 changes: 5 additions & 0 deletions src/pfs_target_uploader/utils/ppp.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def PPPrunStart(
quiet=True,
clustering_algorithm="HDBSCAN",
queue=None,
logger=None,

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Redefining name 'logger' from outer scope (line 24) Note

Redefining name 'logger' from outer scope (line 24)
):
if logger is None:
logger.remove()
logger.add(sys.stderr, level="INFO", enqueue=True)

r_pfi = d_pfi / 2.0

ppp_quiet = quiet
Expand Down
10 changes: 8 additions & 2 deletions src/pfs_target_uploader/widgets/PppResultWidgets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3

import multiprocessing as mp
import sys

import multiprocessing as mp
import numpy as np
import panel as pn
from astropy import units as u
Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(

self.ppp_error_text_2 = (
"<font size=5>⚠️ **Error**</font>\n\n"
f"<font size=3>Calculation stops because time is running out. "
"<font size=3>Calculation stops because time is running out. "
"If you would get the complete outputs, please modify the input list or consult with the observatory. </font>"

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (122/100) Warning

Line too long (122/100)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (122/100) Warning

Line too long (122/100)
)

Expand Down Expand Up @@ -273,7 +273,12 @@ def run_ppp(
clustering_algorithm="HDBSCAN",
quiet=True,
max_exetime=900,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation before block (add 4 spaces). Warning

Wrong hanging indentation before block (add 4 spaces).
logger=None,

Check notice

Code scanning / Pylint (reported by Codacy)

Redefining name 'logger' from outer scope (line 10) Note

Redefining name 'logger' from outer scope (line 10)

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation before block (add 4 spaces). Warning

Wrong hanging indentation before block (add 4 spaces).

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Redefining name 'logger' from outer scope (line 10) Note

Redefining name 'logger' from outer scope (line 10)
):
if logger is None:
logger.remove()
logger.add(sys.stderr, level="INFO", enqueue=True)

if weights is None:
weights = [2.02, 0.01, 0.01]

Expand Down Expand Up @@ -304,6 +309,7 @@ def run_ppp(
quiet,
clustering_algorithm,
ppp_run_results,
logger,
),
)

Expand Down

0 comments on commit 505b308

Please sign in to comment.