From 257871c4e6f808a67cd151ca2dc4c6e59ee382c4 Mon Sep 17 00:00:00 2001 From: scottbelden Date: Wed, 4 Jan 2017 09:37:31 -0500 Subject: [PATCH] add _bg_exc kwarg --- sh.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sh.py b/sh.py index 49abad90..8568110d 100644 --- a/sh.py +++ b/sh.py @@ -586,6 +586,8 @@ def __init__(self, cmd, call_args, stdin, stdout, stderr): if call_args["bg"]: should_wait = False + self._bg_exc = call_args["bg_exc"] + # redirection if call_args["err_to_out"]: stderr = OProc.STDOUT @@ -932,6 +934,9 @@ class Command(object): # ends "bg": False, + # automatically report exceptions for background commands + "bg_exc": True, + "with": False, # prepend the command to every command after it "in": None, "out": None, # redirect STDOUT @@ -1984,7 +1989,7 @@ def timeout_fn(): # RunningCommand.wait() does), because we want the exception to be # re-raised in the future, if we DO call .wait() handle_exit_code = None - if not self.command._spawned_and_waited: + if not self.command._spawned_and_waited and self.command._bg_exc: def fn(exit_code): with process_assign_lock: return self.command.handle_command_exit_code(exit_code)