PrefectHQ / prefect

Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
https://prefect.io
Apache License 2.0
16.32k stars 1.59k forks source link

ShellOperation completes and then errors: RuntimeError: PID 51828 failed with return code 1. #13074

Open discdiver opened 1 year ago

discdiver commented 1 year ago

Runs fine when checking links from a small website such as "https://example.com", perhaps because not opening multiple streams?

Error Reproduction


from prefect import flow
from prefect_shell import ShellOperation

@flow(log_prints=True)
def check_links():

    res = ShellOperation(commands=["linkchecker https://docs.prefect.io"]).run()
    print(res[8:])

if __name__ == "__main__":
    check_links()
Version:             2.10.11
API version:         0.8.4
Python version:      3.10.8
Git commit:          8c651ffc
Built:               Thu, May 25, 2023 2:59 PM
OS/Arch:             darwin/arm64
Profile:             default
Server type:         cloud
prefect-shell             0.1.5                    pypi_0    pypi

Traceback / Example

...
That's it. 1058 links in 1243 URLs checked. 0 warnings found. 2 errors found.
Stopped checking at 2023-06-02 10:19:52-004 (3 minutes, 9 seconds)

10:19:52.136 | ERROR   | Flow run 'axiomatic-otter' - Encountered exception during execution:
Traceback (most recent call last):
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/engine.py", line 742, in orchestrate_flow_run
    result = await flow_call.aresult()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 181, in aresult
    return await asyncio.wrap_future(self.future)
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 194, in _run_sync
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/jeffhale/Desktop/prefect/linkcheck/linkcheck.py", line 9, in check_links
    res = ShellOperation(commands=["linkchecker https://docs.prefect.io"]).run()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/utilities/asyncutils.py", line 260, in coroutine_wrapper
    return call()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 245, in __call__
    return self.result()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 173, in result
    return self.future.result(timeout=timeout)
  File "/Users/jeffhale/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/Users/jeffhale/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 218, in _run_async
    result = await coro
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect_shell/commands.py", line 396, in run
    await shell_process.wait_for_completion()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect_shell/commands.py", line 177, in wait_for_completion
    raise RuntimeError(
RuntimeError: PID 51828 failed with return code 1.
10:19:52.299 | ERROR   | Flow run 'axiomatic-otter' - Finished in state Failed('Flow run encountered an exception. RuntimeError: PID 51828 failed with return code 1.\n')
Traceback (most recent call last):
  File "/Users/jeffhale/Desktop/prefect/linkcheck/linkcheck.py", line 28, in <module>
    check_links()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/flows.py", line 518, in __call__
    return enter_flow_run_engine_from_flow_call(
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/engine.py", line 198, in enter_flow_run_engine_from_flow_call
    retval = from_sync.wait_for_call_in_loop_thread(
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/api.py", line 232, in wait_for_call_in_loop_thread
    return call.result()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 173, in result
    return self.future.result(timeout=timeout)
  File "/Users/jeffhale/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/Users/jeffhale/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 218, in _run_async
    result = await coro
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/client/utilities.py", line 40, in with_injected_client
    return await fn(*args, **kwargs)
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/engine.py", line 292, in create_then_begin_flow_run
    return await state.result(fetch=True)
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/states.py", line 92, in _get_state_result
    raise await get_state_exception(state)
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/engine.py", line 742, in orchestrate_flow_run
    result = await flow_call.aresult()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 181, in aresult
    return await asyncio.wrap_future(self.future)
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 194, in _run_sync
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/jeffhale/Desktop/prefect/linkcheck/linkcheck.py", line 9, in check_links
    res = ShellOperation(commands=["linkchecker https://docs.prefect.io"]).run()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/utilities/asyncutils.py", line 260, in coroutine_wrapper
    return call()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 245, in __call__
    return self.result()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 173, in result
    return self.future.result(timeout=timeout)
  File "/Users/jeffhale/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/Users/jeffhale/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 218, in _run_async
    result = await coro
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect_shell/commands.py", line 396, in run
    await shell_process.wait_for_completion()
  File "/Users/jeffhale/miniforge3/lib/python3.10/site-packages/prefect_shell/commands.py", line 177, in wait_for_completion
    raise RuntimeError(
RuntimeError: PID 51828 failed with return code 1.
egnor commented 1 year ago

Hmm -- linkchecker finds errors in the site, it returns with a nonzero exit code, ShellOperation throws an exception since the command returned failure, and thus the flow failed-- this all seems as expected to me?

bobpeers commented 1 year ago

Not exactly the same but is it safe to assume a return code other than zero is an error? I'm using Robocopy and I get the same error using it in prefect-shell since the return codes under 8 are not errors. This is from the Microsoft site (https://learn.microsoft.com/en-us/troubleshoot/windows-server/backup-and-storage/return-codes-used-robocopy-utility)

image