Open discdiver opened 1 year ago
Much smaller repro example:
from prefect import flow
from prefect_shell import ShellOperation
@flow
def python_version():
with ShellOperation(commands=["python3 --version"]) as op:
process = op.trigger()
process.wait_for_completion()
result = process.fetch_result()
return result
print(python_version())
On my system (Ubuntu 22.04, Linux 5.19.0-43-generic) this generates a feed_data after feed_eof
exception every time. This appears to be a manifestation of https://github.com/PrefectHQ/prefect/issues/6335?
On further investigation, this may be a side effect of using the context block from non-async code, with no async event loop available. In that case, @sync_compatible
will spin up a separate async event loop for each method that's called. That means one event loop will be used to create the ShellOperation
, another one will be used to run op.trigger()
, and so on.
My hypothesis is that since op.trigger()
launches a subprocess with various file descriptors connected and sets up event listeners for those file descriptors, tearing down and rebuilding event loops ends up doing unfortunate things, which cause the internals of the async I/O system to get confused and unhappy.
Probably:
ShellOperation
, always use async with
(from an async function)@sync_compatible
versions of the context-manager operations should be removedany updates?
Thanks for the bumps and the additional MREs here. I'm adding a side note that these MREs run fine for me in 3.0. I'll leave the issue open as I am not certain they are resolved in 2.0.
Reproduction
Use the context block example from the docs (first create folder with today's date):
Traceback