|
1 | 1 | """Structured logger utility for creating JSON logs.
|
2 | 2 |
|
| 3 | +See the delphi_utils README.md for usage examples. |
| 4 | +
|
3 | 5 | The Delphi group uses two ~identical versions of this file.
|
4 | 6 | Try to keep them in sync with edits, for sanity.
|
5 | 7 | https://github.com/cmu-delphi/covidcast-indicators/blob/main/_delphi_utils_python/delphi_utils/logger.py
|
@@ -133,19 +135,17 @@ class LoggerThread():
|
133 | 135 | """
|
134 | 136 | A construct to use a logger from multiprocessing workers/jobs.
|
135 | 137 |
|
136 |
| - the bare structlog loggers are thread-safe but not multiprocessing-safe. |
137 |
| - a `LoggerThread` will spawn a thread that listens to a mp.Queue |
138 |
| - and logs messages from it with the provided logger, |
139 |
| - so other processes can send logging messages to it |
140 |
| - via the logger-like `SubLogger` interface. |
141 |
| - the SubLogger even logs the pid of the caller. |
| 138 | + The bare structlog loggers are thread-safe but not multiprocessing-safe. A |
| 139 | + `LoggerThread` will spawn a thread that listens to a mp.Queue and logs |
| 140 | + messages from it with the provided logger, so other processes can send |
| 141 | + logging messages to it via the logger-like `SubLogger` interface. The |
| 142 | + SubLogger even logs the pid of the caller. |
142 | 143 |
|
143 |
| - this is good to use with a set of jobs that are part of a mp.Pool, |
144 |
| - but isnt recommended for general use |
145 |
| - because of overhead from threading and multiprocessing, |
146 |
| - and because it might introduce lag to log messages. |
| 144 | + This is good to use with a set of jobs that are part of a mp.Pool, but isnt |
| 145 | + recommended for general use because of overhead from threading and |
| 146 | + multiprocessing, and because it might introduce lag to log messages. |
147 | 147 |
|
148 |
| - somewhat inspired by: |
| 148 | + Somewhat inspired by: |
149 | 149 | docs.python.org/3/howto/logging-cookbook.html#logging-to-a-single-file-from-multiple-processes
|
150 | 150 | """
|
151 | 151 |
|
@@ -236,13 +236,11 @@ def pool_and_threadedlogger(logger, *poolargs):
|
236 | 236 | """
|
237 | 237 | Provide (to a context) a multiprocessing Pool and a proxy to the supplied logger.
|
238 | 238 |
|
239 |
| - Emulates the multiprocessing.Pool() context manager, |
240 |
| - but also provides (via a LoggerThread) a SubLogger proxy to logger |
241 |
| - that can be safely used by pool workers. |
242 |
| - The SubLogger proxy interface supports these methods: debug, info, warning, error, |
243 |
| - and critical. |
244 |
| - Also "cleans up" the pool by waiting for workers to complete |
245 |
| - as it exits the context. |
| 239 | + Emulates the multiprocessing.Pool() context manager, but also provides (via |
| 240 | + a LoggerThread) a SubLogger proxy to logger that can be safely used by pool |
| 241 | + workers. The SubLogger proxy interface supports these methods: debug, info, |
| 242 | + warning, error, and critical. Also "cleans up" the pool by waiting for |
| 243 | + workers to complete as it exits the context. |
246 | 244 | """
|
247 | 245 | with multiprocessing.Manager() as manager:
|
248 | 246 | logger_thread = LoggerThread(logger, manager.Queue())
|
|
0 commit comments