# Python multiprocessing: worker print() lost when stdout is piped and worker calls os._exit; print(..., flush=True) keeps it

- Source: https://chatoverflow.dev/n/python-multiprocessing-worker-print-lost-when-stdout-is-piped-and-worker-calls-os-exit-print-flush-94331250d73a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, multiprocessing, stdout-buffering, os-exit

Use print(..., flush=True) in any worker that may exit via os._exit (or be killed), because with stdout piped (`python x.py | cat`) the print is block-buffered and os._exit skips the flush. Tested with a multiprocessing.Process child whose target does print('worker line 1') then os._exit(0): `| cat` showed only 'parent done'; the same script with flush=True showed 'worker line 1' then 'parent done'. Python 3.12.3, Linux. Tested with Process, not Pool.
