Skip to content

Commit

Permalink
read log basedir from context in worker pools
Browse files Browse the repository at this point in the history
This prevents tests from using the default log base dir for workers
  • Loading branch information
pattonw committed Oct 24, 2024
1 parent 052cc50 commit 24cf5c9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 103 deletions.
10 changes: 4 additions & 6 deletions daisy/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def set_log_basedir(path):
else:
LOG_BASEDIR = None


def get_log_basedir():
"""Get the base directory for logging."""
global LOG_BASEDIR
Expand All @@ -30,12 +31,10 @@ def get_log_basedir():

def get_worker_log_basename(worker_id, task_id=None):
"""Get the basename of log files for individual workers."""
global LOG_BASEDIR

if LOG_BASEDIR is None:
return None

basename = LOG_BASEDIR
basename = get_log_basedir()
if basename is None:
return None
if task_id is not None:
basename /= task_id
basename /= f"worker_{worker_id}"
Expand Down Expand Up @@ -64,7 +63,6 @@ def redirect_stdouterr(basename, mode="w"):


def _file_reopen(filename, mode, file_obj):

new = open(filename, mode)
newfd = new.fileno()
targetfd = file_obj.fileno()
Expand Down
1 change: 0 additions & 1 deletion daisy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .block import BlockStatus
from .block_bookkeeper import BlockBookkeeper
from .context import Context
from .logging import get_log_basedir
from .messages import (
AcquireBlock,
BlockFailed,
Expand Down
1 change: 0 additions & 1 deletion daisy/task_worker_pools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .context import Context
from .logging import get_log_basedir
from .server_observer import ServerObserver
from .worker_pool import WorkerPool
import logging
Expand Down
2 changes: 2 additions & 0 deletions daisy/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def _spawn_wrapper(self):
try:

os.environ[self.context.ENV_VARIABLE] = self.context.to_env()
log_base = self.context.get("logdir", daisy_logging.get_log_basedir())
daisy_logging.set_log_basedir(log_base)

log_base = daisy_logging.get_worker_log_basename(
self.worker_id, self.context.get("task_id", None)
Expand Down
8 changes: 0 additions & 8 deletions tests/conf.py

This file was deleted.

8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

from daisy.logging import set_log_basedir


@pytest.fixture(autouse=True)
def logdir(tmp_path):
set_log_basedir(tmp_path / "daisy_logs")
87 changes: 0 additions & 87 deletions tests/tmpdir_test.py

This file was deleted.

0 comments on commit 24cf5c9

Please sign in to comment.