multiprocessing
차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판이전 판다음 판 | 이전 판 | ||
multiprocessing [2020/06/05 17:44] – rex8312 | multiprocessing [2024/03/23 02:38] (현재) – 바깥 편집 127.0.0.1 | ||
---|---|---|---|
줄 1: | 줄 1: | ||
====== multiprocessing ====== | ====== multiprocessing ====== | ||
+ | |||
+ | * 자식프로세스 출력 redirection | ||
+ | |||
+ | <code python> | ||
+ | |||
+ | import app | ||
+ | import io | ||
+ | import sys | ||
+ | from multiprocessing import Process | ||
+ | |||
+ | def run_app(some_param): | ||
+ | sys.stdout = io.TextIOWrapper(open(sys.stdout.fileno(), | ||
+ | app.run() | ||
+ | |||
+ | app_process = Process(target=run_app, | ||
+ | app_process.start() | ||
+ | # Use app_process.termninate() for python <= 3.7. | ||
+ | app_process.kill() | ||
+ | |||
+ | # https:// | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | original_stdout = sys.stdout | ||
+ | buffer = deque(maxlen=128) | ||
+ | |||
+ | class IOLoggerWrapper(io.StringIO): | ||
+ | def write(self, string): | ||
+ | buffer.append(string) | ||
+ | return len(string) | ||
+ | | ||
+ | root = logging.getLogger() | ||
+ | handler = logging.StreamHandler(IOLoggerWrapper()) | ||
+ | formatter = logging.Formatter(" | ||
+ | handler.setFormatter(formatter) | ||
+ | root.addHander(handler) | ||
+ | |||
+ | class IOWrapper(io.StringIO): | ||
+ | def write(self, string): | ||
+ | original_stdout.write(string) | ||
+ | buffer.append(string) | ||
+ | return len(string) | ||
+ | | ||
+ | io_wrapper = IOWrapper() | ||
+ | sys.stdout = io_wrapper | ||
+ | sys.stderr = io_wrapper | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== multiprocessing 대체 모듈 ===== | ||
* Uber Fiber | * Uber Fiber | ||
줄 10: | 줄 60: | ||
* Array 공유 | * Array 공유 | ||
* https:// | * https:// | ||
+ |
multiprocessing.1591379073.txt.gz · 마지막으로 수정됨: (바깥 편집)