-
Notifications
You must be signed in to change notification settings - Fork 36
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
Implemented __del__
to clean up hanging coroutines
#263
Conversation
Thanks for doing this! Good catch on this. It seems like pre-commit is unhappy about something that Alon fixed and was recently merged into main. Can you merge main into this and make sure the pre-commit check passes. Let me know if you need help or want to chat. Thanks again for doing this! |
Also, do you have any references for the close method on coroutine? I only found the Going off the generator documentation, we may need to catch and throw some exceptions. Catch from within the del method and throw from within the task execution, maybe. Edit: Found it: Looking at the source code for the close method, I think it might be best to go with your other suggestion in the issue report. This is because both the |
I don't think its totally unreasonable to deal with exceptions in Reading more about how This might happen if the coroutine gets cancelled while its in a Ironically, one solution might be to wrap the call to |
Honestly I think we should not try to catch the exceptions that might come from The remaining question then is if the behavior of these errors becoming warnings because of being called in |
I changed it to do explicit cancelling instead of using |
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.
Thanks for making this change. I do think this is a better method. Now we know if we see that warning that something is truly going wrong.
Edit: Do you still think we should put a try-except around close()
?
I think we shouldn't because an error indicates the coroutine didn't exit properly which is a problem the user should know about and suggests something should be fixed either in BQSKit or the user's code. I could try to be fancy and catch any errors and after closing all the tasks, I could re-raise the first error it encountered, or something along those lines. |
I guess the ‘if coro is None` check needs to be there after all |
bqskit/runtime/worker.py
Outdated
@@ -338,6 +347,10 @@ def _handle_cancel(self, addr: RuntimeAddress) -> None: | |||
if not t.is_descendant_of(addr) | |||
] | |||
|
|||
# if there was an error earlier, raise it now | |||
if error is not None: | |||
raise error |
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.
Why do you delay the raise? Shouldn't the system crash immediately, or is this to test something?
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.
The idea is to finish cancelling tasks as much as possible before letting the system crash. Although I suppose if its gonna crash, the system isn't going to be in a great state anyway. Should I just let it crash immediately?
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.
Yeah, let it crash immediately.
@edyounis This one should be good to merge now. It includes all the tweaks we talked about. |
This is intended to be a simple fix for #262
Currently, when
RuntimeTask
s are cancelled, they sometimes end up garbage collected with coroutines that are neverawait
ed. When those coroutines get garbage collected,RuntimeWarning
s appear.I've implemented
__del__
forRuntimeTask
which simplyclose()
s the coroutine, which lets Python know its ok that the coroutine was never used.