Logging
How to use logging with multiprocessing
Minimal Example
import multiprocessing as mp
from subnet.utils.logging import configure_subprocess_logging, get_logger
logger = get_logger(__name__)
class MVP(mp.Process):
def __init__():
super().__init__()
self.stop = mp.Event()
def run(self):
configure_subprocess_logging()
self.logger = get_logger(__name__)
def example_function(self):
"""Child functions use the child process logging"""
self.logger.info("Logging example")
def shutdown(self, timeout: float = 5.0):
"""Shutdown uses the top-level logging"""
if not self.stop.is_set():
self.stop.set()
if self.is_alive():
self.join(3)
if self.is_alive():
logger.warning("Consensus did not shut down within the grace period; terminating it the hard way")
self.terminate()
else:
logger.warning("Consensus shutdown had no effect, the process is already dead")Last updated