Skip to content
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

[core] actor object not garbage collected when being killed #50048

Open
raulchen opened this issue Jan 24, 2025 · 0 comments
Open

[core] actor object not garbage collected when being killed #50048

raulchen opened this issue Jan 24, 2025 · 0 comments
Labels
core Issues that should be addressed in Ray Core P1 Issue that should be fixed within a few weeks

Comments

@raulchen
Copy link
Contributor

Sometimes an actor can depend on external resources that need be cleaned up upon actor termination. and users would want to do the clean up in Actor.__del__.

But currently the actor object is referenced by global_worker.actors, thus Actor.__del__ won't be called.

We should add a callback in CoreWorker::HandleKillActor to remove the reference.

Repro:

import time
import ray


@ray.remote
class Actor:
    def __init__(self):
        print("Actor.__init__")

    def ping(self):
        # Without the following, `__del__` won't be called.
        worker = ray._private.worker.global_worker
        actor_id = worker.actor_id
        del worker.actors[actor_id]
        return ""

    def __del__(self):
        print("Actor.__del__")


actor = Actor.remote()
ray.get(actor.ping.remote())

del actor
time.sleep(3)

Related issue for Ray Data: #49929

@raulchen raulchen added core Issues that should be addressed in Ray Core P1 Issue that should be fixed within a few weeks labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues that should be addressed in Ray Core P1 Issue that should be fixed within a few weeks
Projects
None yet
Development

No branches or pull requests

1 participant