Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work out error handling when calling R from subprocess. #49

Open
grabear opened this issue Mar 31, 2019 · 3 comments
Open

Work out error handling when calling R from subprocess. #49

grabear opened this issue Mar 31, 2019 · 3 comments

Comments

@grabear
Copy link
Member

grabear commented Mar 31, 2019

Is this the only exception we might hit?

Originally posted by @santina in #42

@grabear grabear mentioned this issue Mar 31, 2019
@grabear
Copy link
Member Author

grabear commented Mar 31, 2019

What if we actually got an error in the system_r_call? i.e. stdout is not actually the information we want. We should handle that.

Originally posted by @santina in #42

@sdhutchins
Copy link
Member

I think with the proc.communicate function it's typically best to use the TimeoutExpired exception since that's the main thing that function depends on is a timeout.

However, you could do a bigger catch like...

try:
    recommended_pkgs = sp.Popen([Rcmd], stderr=sp.PIPE, stdout=sp.PIPE, 
                                shell=True, encoding='utf-8')
    try:
        stdout, stderr = recommended_pkgs.communicate(timeout=15)
    except TimeoutExpired:
        recommended_pkgs.kill()
        stdout, stderr = recommended_pkgs.communicate()
    return stdout, stderr
except subprocess.CalledProcessError as err:
  # There was an error - command exited with non-zero code
  logger.error(err)

@sdhutchins
Copy link
Member

It may be better to write functions for both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants