Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
instantiate multiprocessing.log_to_stderr lazily (#2166)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelgrus committed Dec 11, 2018
1 parent 021471a commit 41c7196
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions allennlp/data/dataset_readers/multiprocess_dataset_reader.py
Expand Up @@ -8,8 +8,24 @@
from allennlp.data.dataset_readers.dataset_reader import DatasetReader
from allennlp.data.instance import Instance

logger = log_to_stderr() # pylint: disable=invalid-name
logger.setLevel(logging.INFO)
class logger:
"""
multiprocessing.log_to_stderr causes some output in the logs
even when we don't use this dataset reader. This is a small hack
to instantiate the stderr logger lazily only when it's needed
(which is only when using the MultiprocessDatasetReader)
"""
_logger = None

@classmethod
def info(cls, message: str) -> None:
# pylint: disable=no-self-use
if cls._logger is None:
cls._logger = log_to_stderr()
cls._logger.setLevel(logging.INFO)

cls._logger.info(message)


def _worker(reader: DatasetReader,
input_queue: Queue,
Expand Down

0 comments on commit 41c7196

Please sign in to comment.