子进程中的父记录器
Parent loggers in child processes
在 Python 上的 Logging Cookbook 中, 部分有以下评论“更多
详尽的多处理示例":
# The worker process configuration is just a QueueHandler attached to the
# root logger, which allows all messages to be sent to the queue.
# We disable existing loggers to disable the "setup" logger used in the
# parent process. This is needed on POSIX because the logger will
# be there in the child following a fork().
# The listener process configuration shows that the full flexibility of
# logging configuration is available to dispatch events to handlers however
# you want.
# We disable existing loggers to disable the "setup" logger used in the
# parent process. This is needed on POSIX because the logger will
# be there in the child following a fork().
在子进程中使用父记录器到底有什么问题?
(潜在的)问题是,如果父进程和子进程一样继续记录,它们可能会记录到相同的处理程序(因为 fork
如何在 POSIX 上工作) 并且您不能保证同时从两个进程写入单个文件会正常工作。请参阅食谱中 this section 的第一段。
在 Python 上的 Logging Cookbook 中, 部分有以下评论“更多 详尽的多处理示例":
# The worker process configuration is just a QueueHandler attached to the
# root logger, which allows all messages to be sent to the queue.
# We disable existing loggers to disable the "setup" logger used in the
# parent process. This is needed on POSIX because the logger will
# be there in the child following a fork().
# The listener process configuration shows that the full flexibility of
# logging configuration is available to dispatch events to handlers however
# you want.
# We disable existing loggers to disable the "setup" logger used in the
# parent process. This is needed on POSIX because the logger will
# be there in the child following a fork().
在子进程中使用父记录器到底有什么问题?
(潜在的)问题是,如果父进程和子进程一样继续记录,它们可能会记录到相同的处理程序(因为 fork
如何在 POSIX 上工作) 并且您不能保证同时从两个进程写入单个文件会正常工作。请参阅食谱中 this section 的第一段。