Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process updates on windows not working #1

Open
koenvo opened this issue May 23, 2023 · 0 comments
Open

Process updates on windows not working #1

koenvo opened this issue May 23, 2023 · 0 comments

Comments

@koenvo
Copy link
Contributor

koenvo commented May 23, 2023

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant