belikor / lbrytools

Python library with useful methods built on top of the lbrynet client from the LBRY project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle the returncode of the `lbrynet` process better

belikor opened this issue · comments

Currently the lbrynet command is run through subprocess; if the returncode is 1, this indicates an error and it abruptly terminates the Python script.

    get_cmd = ["lbrynet",
               "get",
               "'lbry://@asaaa#5/a#b'"]
    output = subprocess.run(get_cmd,
                            capture_output=True,
                            check=True,
                            text=True)
    if output.returncode == 1:
        print(f"Error: {output.stderr}")
        sys.exit(1)

Although lbrynet seems to be quite stable, and it rarely returns an error, this should be handled better, and exit should be avoided, as it terminates the complete script where the function is being used.

This returncode may be exclusive to running subprocess. Maybe by solving issue #1, we can avoid this altogether.

As mentioned in #1, the reason we do it like this at the moment is historical. We started by copying the code from another programmer, and we just continued that.

With various commits from 560ddcf to 36479e3 now no function uses subprocess; they all send messages to the JSON-RPC server.

So issue #1 is solved, and we can close this as well.