Skip to content

Commit

Permalink
do not initialize logging on import
Browse files Browse the repository at this point in the history
  • Loading branch information
fjetter committed May 6, 2024
1 parent 1ec61a1 commit cc757f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion distributed/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging.config
import os
import sys
import threading
from collections.abc import Callable
from typing import Any

Expand Down Expand Up @@ -212,4 +213,13 @@ def get_loop_factory() -> Callable[[], asyncio.AbstractEventLoop] | None:
)


initialize_logging(dask.config.config)
_LOGGING_CONFIGURED = False
_LOG_CONFIGURE_LOCK = threading.Lock()


def ensure_logging_configured() -> None:
global _LOGGING_CONFIGURED
with _LOG_CONFIGURE_LOCK:
if not _LOGGING_CONFIGURED:
_LOGGING_CONFIGURED = True
initialize_logging(dask.config.config)
2 changes: 2 additions & 0 deletions distributed/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
)
from distributed.comm.core import Listener
from distributed.compatibility import PeriodicCallback
from distributed.config import ensure_logging_configured
from distributed.counter import Counter
from distributed.diskutils import WorkDir, WorkSpace
from distributed.metrics import context_meter, time
Expand Down Expand Up @@ -647,6 +648,7 @@ async def start_unsafe(self):

@final
async def start(self):
ensure_logging_configured()
async with self._startup_lock:
if self.status == Status.failed:
assert self.__startup_exc is not None
Expand Down
2 changes: 2 additions & 0 deletions distributed/deploy/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from dask.widgets import get_template

from distributed.compatibility import PeriodicCallback
from distributed.config import ensure_logging_configured
from distributed.core import Status
from distributed.deploy.adaptive import Adaptive
from distributed.metrics import time
Expand Down Expand Up @@ -67,6 +68,7 @@ def __init__(
name=None,
scheduler_sync_interval=1,
):
ensure_logging_configured()
self._loop_runner = LoopRunner(loop=loop, asynchronous=asynchronous)
self.__asynchronous = asynchronous

Expand Down

0 comments on commit cc757f1

Please sign in to comment.