Skip to content

Commit

Permalink
Allow control over output and environment for nodes
Browse files Browse the repository at this point in the history
Each node that creates a subprocess now has control over the output
handles and environment variables for the subprocess.  This will
enable environment-based logging (as ffmpeg uses) or logging based on
a file handle.

This is a step toward logging support.

Issue #12

Change-Id: I717d411e4b708eeaf05af03e1a16602336c2d065
  • Loading branch information
joeyparrish committed Oct 4, 2019
1 parent 045bef3 commit f8c4bb8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions streamer/node_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import abc
import enum
import os
import shlex
import subprocess
import time
Expand Down Expand Up @@ -47,20 +48,33 @@ def start(self):
"""
pass

def _create_process(self, args):
def _create_process(self, args, env={}, merge_env=True, stdout=None,
stderr=None):
"""A central point to create subprocesses, so that we can debug the
command-line arguments.
Args:
args: An array of strings, the command line of the subprocess.
env: A dictionary of environment variables to pass to the subprocess.
merge_env: If true, merge env with the parent process environment.
Returns:
The Popen object of the subprocess.
"""
if merge_env:
child_env = os.environ.copy()
child_env.update(env)
else:
child_env = env

# Print arguments formatted as output from bash -x would be.
# This makes it easy to see the arguments and easy to copy/paste them for
# debugging in a shell.
print('+ ' + ' '.join([shlex.quote(arg) for arg in args]))
return subprocess.Popen(args, stdin = subprocess.DEVNULL)

return subprocess.Popen(args,
env=child_env,
stdin=subprocess.DEVNULL,
stdout=stdout, stderr=stderr)

def check_status(self):
"""Returns the current ProcessStatus of the node."""
Expand Down

0 comments on commit f8c4bb8

Please sign in to comment.