Do not reopen stdout and stderr on fork

This is no longer necessary, since we switched to forkserver
This commit is contained in:
George Tsiamasiotis 2024-10-02 18:44:12 +03:00
parent 2e432601b6
commit 32787e2789

View File

@ -2,7 +2,6 @@ import atexit
import logging
import multiprocessing as mp
import os
import sys
import threading
from collections import deque
from logging.handlers import QueueHandler, QueueListener
@ -53,19 +52,6 @@ def _stop_logging() -> None:
log_listener = None
# When a multiprocessing.Process exits, python tries to flush stdout and stderr. However, if the
# process is created after a thread (for example a logging thread) is created and the process fork
# happens while an internal lock is held, the stdout/err flush can cause a deadlock.
#
# https://github.com/python/cpython/issues/91776
def reopen_std_streams() -> None:
sys.stdout = os.fdopen(1, "w")
sys.stderr = os.fdopen(2, "w")
os.register_at_fork(after_in_child=reopen_std_streams)
# based on https://codereview.stackexchange.com/a/17959
class LogPipe(threading.Thread):
def __init__(self, log_name: str):