Skip to content

Commit

Permalink
Fixing bug in errors code. Fixes #104
Browse files Browse the repository at this point in the history
Adds more exception handling around setting stdout/stderr streams
in bash apps.
  • Loading branch information
yadudoc committed Feb 28, 2018
1 parent f61400a commit 376d798
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
6 changes: 5 additions & 1 deletion parsl/app/bash_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ def remote_side_bash_executor(func, *args, **kwargs):

try:
std_out = open(stdout, 'w') if stdout else None
except Exception as e:
raise pe.BadStdStreamFile(stdout, e)

try:
std_err = open(stderr, 'w') if stderr else None
except Exception as e:
raise pe.BadStdStreamFile([stdout, stderr], e)
raise pe.BadStdStreamFile(stderr, e)

returncode = None
try:
Expand Down
8 changes: 5 additions & 3 deletions parsl/app/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ class BadStdStreamFile(ParslError):
exception object
'''

def __init__(self, outputs):
def __init__(self, outputs, exception):
super().__init__()
self.outputs = outputs
self._outputs = outputs
self._exception = exception

def __repr__(self):
return "Paths:[{}]".format(self.outputs)
return "FilePath:[{}] Exception:{}".format(self._outputs,
self._exception)

def __str__(self):
return self.__repr__()
Expand Down
63 changes: 63 additions & 0 deletions parsl/tests/test_threads/test_bash_stdout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
''' Testing bash apps
'''
import parsl
import parsl.app.errors as perror
from parsl import *

print("Parsl version: ", parsl.__version__)

# parsl.set_stream_logger()
workers = ThreadPoolExecutor(max_workers=8)
dfk = DataFlowKernel(executors=[workers])


@App('bash', dfk)
def echo_to_streams(msg, stderr='std.err', stdout='std.out'):
return 'echo "{0}"; echo "{0}" >&2'.format(msg)


def test_bad_stdout():
''' Testing bad stdout file
'''
stdout = "/x/test_bad_stdout.stdout"
stderr = "test_bad_stdout.stderr"
fu = echo_to_streams("Hello world", stderr=stderr, stdout=stdout)

try:
fu.result()
except Exception as e:
assert isinstance(
e, perror.BadStdStreamFile), "Expected BadStdStreamFile, got :{0}".format(type(e))

return


def test_bad_stderr():
''' Testing bad stderr file
'''
stdout = "test_bad_stdout.stdout"
stderr = "/x/test_bad_stdout.stderr"
fu = echo_to_streams("Hello world", stderr=stderr, stdout=stdout)

try:
fu.result()
except Exception as e:
assert isinstance(
e, perror.BadStdStreamFile), "Expected BadStdStreamFile, got :{0}".format(type(e))

return


if __name__ == '__main__':

parser = argparse.ArgumentParser()
parser.add_argument("-c", "--count", default="10",
help="Count of apps to launch")
parser.add_argument("-d", "--debug", action='store_true',
help="Count of apps to launch")
args = parser.parse_args()

if args.debug:
parsl.set_stream_logger()

y = test_bad_stdout()

0 comments on commit 376d798

Please sign in to comment.