Just spent a couple hours debugging to realize tha...
# ask-community
m
Just spent a couple hours debugging to realize that prefect tasks don't play nicely with yields. It's hard to debug this without a warning or error being thrown. Might also be worth mentioning this in the prefect documentation!
a
Hey! Can you say more about how you’d like it to behave? We’re actively improving how our tasks behave in general but would love to make sure we bake in what you’re looking for if we can
m
Best case scenario it yields just like a regular python yield
a
cc @Chris White who’s been t’asking around for feedback
m
Running it in a task shouldn’t silently alter the alter the behaviour
c
The tricky part from prefect's perspective is that tasks are a part of dependency graphs, so once you yield and the task stays "running", dependency semantics break down; that being said, we had a working prototype with
yield
at some point recently, so there's a decent chance that our next major version release (3.0) will be able to handle this.
m
Yeah I figured there'd be technical hangups in getting it to work. I think thats totally fine - but maybe throw a warning if someone does it then. Or if that's a pain as well, maybe documenting it clearly would be helpful if nothing else. Right now it causes silent undocumented bugs which is a huge pain
c
Yea I hear ya and agree - I’ll see if a basic inspect on the function is sufficient to detect if it’s a generator and also see if we can get this working for our 3.0 release
w
Sorry didn't get it what is the issue with using yield inside a task. Are you saying that it keeps on the "running" state indefinitely? Because I have a task that yields and this thread came as surprise to me.
m
It probably isn't yielding as you'd expect, I think current behaviour collects all yields and returns them together as one result. Or possibly only returns the final yield
c
I've confirmed that we will be able to support generators in our 3.0 release, so I'll revisit this thread when we have a release candidate to experiment with!
🔥 1
Hey everyone on this thread! Following up here, we've got an open PR for 3.0 that adds generator task support: https://github.com/PrefectHQ/prefect/pull/13820, so this should be available to experiment with in the next 3.0rc release (which should go out today or tomorrow)
🔥 1