-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[data] Trigger UDF.__del__
when an actor is about to exit
#49929
Conversation
Signed-off-by: Hao Chen <[email protected]>
Signed-off-by: Hao Chen <[email protected]>
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.
Test locally and it works like charm
def on_exit(self): | ||
"""Called when the actor is about to exist. | ||
This enables performing cleanup operations via `UDF.__del__`. | ||
|
||
Note, this only ensures cleanup is performed when the job exists gracefully. | ||
If the driver or the actor is forcefully killed, `__del__` will not be called. | ||
""" | ||
# `_map_actor_context` is a global variable that references the UDF object. | ||
# Delete it to trigger `UDF.__del__`. | ||
del ray.data._map_actor_context | ||
ray.data._map_actor_context = 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.
Is there a reason we need to introduce an explicit method rather than overriding _MapWorker.__del__
? I imagine if we override __del__
, we'll implicitly do the cleanup when we run del self._running_actors[actor]
.
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.
I also tried that. But it looks like that Ray Core doesn't call Actor.__del__
when killing an actor. cc @jjyao
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.
Signed-off-by: Hao Chen <[email protected]>
…ect#49929) ## Why are these changes needed? A stateful UDF may depend on external resources that may need to be cleaned up at the end. This PR allows performing the cleanup operations via `UDF.__del__` Note, this only ensures cleanup is performed when the job exists gracefully. If the driver or the actor is forcefully killed, `__del__` will not be --------- Signed-off-by: Hao Chen <[email protected]> Signed-off-by: Eric Tang <[email protected]>
Why are these changes needed?
A stateful UDF may depend on external resources that may need to be cleaned up at the end.
This PR allows performing the cleanup operations via
UDF.__del__
Note, this only ensures cleanup is performed when the job exists gracefully.
If the driver or the actor is forcefully killed,
__del__
will not be called.Related issue number
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.