-
Notifications
You must be signed in to change notification settings - Fork 43
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
[MOD-3553]: Function.spawn() returns a FunctionCall for generators & add iter_gen to get results #2155
Conversation
…s a function call (not | None)
7d98964
to
2619da9
Compare
modal/functions.py
Outdated
return await self._invocation().poll_function(timeout=timeout) | ||
|
||
async def iter_gen(self) -> AsyncGenerator[Any, None]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should call it get_gen()
instead? As a corollary to Function.remote()
and Function.remote_gen()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt @aksh-at ? I have a vague memory we discussed adding generator support to FunctionCall like ~2 years ago 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep makes sense!
@kramstrom @freider thanks for moving this along! Would've been extremely fun to have the PR I opened merged into Modal 😂 but glad to see this in-progress and done the right way I'll close that PR and watch this one 🫡 thanks so much |
…rom/add-iter-gen-to-function-call
Sorry about that! I did rebase from your branch so at least you will be in the commit history though! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! Not 100% happy that from_id requires is_generator, but it's probably sufficiently rare that we could leave it like that for now (instead of adding new rpcs to be able to fetch the function's generator/function type from server based on id) - in particular since the requesting party needs to know the function type anyways to be able to use it.
@kramstrom @freider glad to say that I just ran into this again, did fn_calls: list[modal.functions.FunctionCall[MyType]] = [my_function.spawn(job) for job in jobs] No type-checker complaints that Now time to make |
Related to #2145
Function.spawn()
now always returns a_FunctionCall
(no need to check for optional anymore)_FunctionCall.get()
for generators_FunctionCall.iter_gen()
which should be used instead