-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
On Windows we use the spawn start method for multiprocessing Pool. This somehow breaks the logger used in run_task
ChatGPT:
import logging
import logging.handlers
import multiprocessing
import os
def worker_process(q, i):
qh = logging.handlers.QueueHandler(q)
root = logging.getLogger()
root.addHandler(qh)
root.setLevel(logging.INFO)
logging.info(f'Hello from worker {i}')
def logger_thread(q):
while True:
try:
record = q.get()
if record is None: # We send this as a sentinel to tell the listener to quit.
break
logger = logging.getLogger(record.name)
logger.handle(record) # No level or filter logic applied - just do it!
except Exception:
import sys, traceback
print('Problem:', file=sys.stderr)
traceback.print_exc(file=sys.stderr)
def main():
q = multiprocessing.Queue()
log_thread = multiprocessing.Process(target=logger_thread, args=(q,))
log_thread.start()
workers = []
for i in range(5):
wp = multiprocessing.Process(target=worker_process, args=(q, i))
workers.append(wp)
wp.start()
for wp in workers:
wp.join()
# Tell the logging server to shut down
q.put(None)
log_thread.join()
if __name__ == '__main__':
main()
Metadata
Metadata
Assignees
Labels
No labels