def _run_process(self, name, cmd): Log.info("Running %s process as %s" % (name, cmd)) try: # stderr is redirected to stdout so that it can more easily be logged. stderr has a max buffer # size and can cause the child process to deadlock if it fills up process = subprocess.Popen(cmd.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=cmd.env, universal_newlines=True, bufsize=1) proc.async_stream_process_stdout(process, stdout_log_fn(name)) except Exception: Log.info("Exception running command %s", cmd) traceback.print_exc() return process
def _run_process(self, name, cmd, env_to_exec=None): Log.info("Running %s process as %s" % (name, ' '.join(cmd))) try: # stderr is redirected to stdout so that it can more easily be logged. stderr has a max buffer # size and can cause the child process to deadlock if it fills up process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env_to_exec, bufsize=1) proc.async_stream_process_stdout(process, stdout_log_fn(name)) except Exception: Log.info("Exception running command %s", cmd) traceback.print_exc() return process
def test_async_stream_process_stdout(self): ret = StringIO(u'hello\nworld\n') log_fn = Mock() with patch("subprocess.Popen") as mock_process: mock_process.stdout = ret thread = proc.async_stream_process_stdout(mock_process, log_fn) thread.join() log_fn.assert_has_calls([call(u'hello\n'), call(u'world\n')])
def test_async_stream_process_stdout(self): ret = StringIO(u'hello\nworld\n') log_fn = Mock() with patch("subprocess.Popen") as mock_process: mock_process.stdout = ret thread = proc.async_stream_process_stdout(mock_process, log_fn) thread.join() log_fn.assert_has_calls([call(u'hello\n'), call(u'world\n')])