Skip to content

Commit

Permalink
Make output UNBUFFERED for python children
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Jun 9, 2024
1 parent 84f08fd commit 89ec775
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/duct.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,18 @@ def execute(args):
full_command = " ".join([str(args.command)] + args.inner_args)
print(f"{Colors.OKCYAN}duct is executing {full_command}...")
print(f"Log files will be written to {formatted_output_prefix}{Colors.ENDC}")

# Tell child Python processes to not buffer output and thus flush it "real-time".
# TODO: since it changes underlying environment, we might want to
# make it not optional.
env = os.environ.copy()
env["PYTHONUNBUFFERED"] = "1"
process = subprocess.Popen(
[str(args.command)] + args.inner_args,
stdout=stdout_file,
stderr=stderr_file,
preexec_fn=os.setsid,
env=env,
)
try:
session_id = os.getsid(process.pid) # Get session ID of the new process
Expand Down

0 comments on commit 89ec775

Please sign in to comment.