-
Notifications
You must be signed in to change notification settings - Fork 0
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
don't use __del__, call it manually #2
base: fix/cancel_goal
Are you sure you want to change the base?
Conversation
You're not changing where the function is called? |
@Timple as stated in the PR description above, I think it is better to first choose 1 of the possible fixes, and when we have chosen 1, I will fix the tests :). (Btw I don't think |
I completely agree on the fact that relying on del should be avoided as things become real tricky when dealing with threading. And ofcourse what you have suggested is a valid alternative solution. But the main question is who will be using this code? I don't have context over this package, but some things to take into account:
|
@alireza-moayyedi don't you have the problem that the shutdown can happen twice? |
From the issues found, I conclude that this part of the code is not used by much people. |
@RichardvdK Afaik, in ROS2 it should be fine. I just did the following test and had no problem:
I would just do what @Timple suggested since I personally do not have any context on this package and he knows who, how, uses it. |
Using
__del__
to stop the executor and wait for the thread is seen as bad practice and (The only required property of Python garbage collection is that it happens after all references have been deleted, so this might not necessarily happen right after and might not happen at all.) does_ not work most of the time. I encountered that this node's spin() thread was never cleanly terminated. When calling the renamed shutdown() now (without an exception), the spin() thread can finish cleanly.This DOES require manually calling the shutdown() method wherever you want to shutdown this node. So after approval of this method, I should rewrite the tests that use this Class.
Another way is to pass a Node to the IntrospectionServer() and IntrospectionClient() classes so they don't make new SingleThreadedExecutors. In this way, even exceptions can be handled better I think.
Another way is maybe to make the spin() thread a Daemon thread, but this resulted in the following error codes/ warnings while running the executive: