Repository navigation
Convert Node and Context to use C++ Classes - #771
Conversation
Signed-off-by: ahcorde <[email protected]>
e9365a8 to
527fb10
Compare
|
The GuardCondition PR is in, I open this PR for review. The test |
| node.destroy_node() | ||
| with pytest.raises(InvalidHandle): | ||
| node.destroy_node() | ||
| # with pytest.raises(InvalidHandle): |
There was a problem hiding this comment.
@ahcorde hmm, doesn't it throw anymore? Can we destroy a node twice?
Signed-off-by: ahcorde <[email protected]>
| try: | ||
| node = rclpy.create_node('test_node2', context=context) | ||
| node.destroy_node() | ||
| # with pytest.raises(InvalidHandle): |
| node.destroy_node() | ||
| # handle valid because it's still being used | ||
| with node.handle: | ||
| pass |
There was a problem hiding this comment.
# handle valid because it's still being used
This was an intentional change in #739 with Destroyable. Once someone asks to destroy a Destroyable, it will block new uses of it. The Handle class allowed new uses as long as someone else was already using it, but that could lead to two threads blocking destruction forever as long as their uses overlapped.
There was a problem hiding this comment.
That makes total sense. I still think we should test that usage attempts after destruction requests fail.
| node.destroy_node() | ||
| with pytest.raises(InvalidHandle): | ||
| node.destroy_node() | ||
| node.destroy_node() |
| with node.handle: | ||
| node.handle.destroy() | ||
| with node.handle: | ||
| pass |
| def __del__(self): | ||
| self.destroy() | ||
|
|
||
| def destroy(self): |
There was a problem hiding this comment.
There was a problem hiding this comment.
Ah weird, the github UI is still showing it for me. I'll look at the new commits locally :-/
| def handle(self, value): | ||
| raise AttributeError('handle cannot be modified after node creation') | ||
|
|
||
| def __del__(self): |
There was a problem hiding this comment.
This seems unnecessary. All the python objects on the node will already destroy themselves when they're garbage collected.
There was a problem hiding this comment.
But we should call here destroy_node() otherwise the destruction fails
There was a problem hiding this comment.
But we should call here
destroy_node()otherwise the destruction fails
What does that mean? What does the failure look like?
There was a problem hiding this comment.
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
This along with an extra call to `destroy_node()` in `Node.__del__` was causing a segfault in the test_publisher test. The problem is `destroy_when_not_in_use()` was being called twice, and the second time is now a problem because rcl_ptrs_ is dereferenced in the qos_event destroy() method. Signed-off-by: Shane Loretz <[email protected]>
This should not be required. If it is, it means there's a bug that shows when the Node is garbage collected. Signed-off-by: Shane Loretz <[email protected]>
The order of the pointers in the RclPtrs structs is important. Things at the bottom are destroyed first, so children must be placed underneath the parent's that must be kept alive. Signed-off-by: Shane Loretz <[email protected]>
…773) * Rough pass converting everything Signed-off-by: Shane Loretz <[email protected]> * Fixes to get copy destruction order working Signed-off-by: Shane Loretz <[email protected]> * Fix qos_event test flakiness Signed-off-by: Shane Loretz <[email protected]> Signed-off-by: ahcorde <[email protected]>
f36aaac to
33b848d
Compare
I think those are fine actually. I would like to get rid of the |
Signed-off-by: ahcorde <[email protected]>
sloretz
left a comment
There was a problem hiding this comment.
Just some nitpicks, otherwise this PR looks pretty good!
|
|
||
| void | ||
| init(py::list pyargs, py::capsule pycontext, size_t domain_id) | ||
| init(py::list pyargs, Context & context, size_t domain_id) |
There was a problem hiding this comment.
Is the idea to move the logic in init(...) into a constructor of Context? That sounds fine to me. I don't think the zero initialized context is used anywhere else.
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
sloretz
left a comment
There was a problem hiding this comment.
LGTM! Thanks for iterating! 🎉
* Convert Publisher and Subscription to use C++ Classes (#756) * Convert Publisher and Subscription to C++ Classes Signed-off-by: ahcorde <[email protected]> * Fixed destructor issues Signed-off-by: ahcorde <[email protected]> * [pub/sub 756 addition] use std::shared_ptr holder type and shared_from_this (#757) * Use std::shared_ptr holder type Signed-off-by: Shane Loretz <[email protected]> * Use shared_from_this for pub/sub Signed-off-by: Shane Loretz <[email protected]> * Make Timer keep Clock wrapper Signed-off-by: Shane Loretz <[email protected]> * Fixed publisher and subscription destructors Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Fixed docs Signed-off-by: ahcorde <[email protected]> Co-authored-by: Shane Loretz <[email protected]> * Use py::class_ for rcl_action_goal_handle_t (#751) * Class object Signed-off-by: Greg Balke <[email protected]> * Python adjustments Signed-off-by: Greg Balke <[email protected]> * Adjustments to server and enum Signed-off-by: Greg Balke <[email protected]> * Adjust destructor calls Signed-off-by: Greg Balke <[email protected]> * Clear out destructor Signed-off-by: Greg Balke <[email protected]> * Do what rclcpp did Signed-off-by: Greg Balke <[email protected]> * Remove iostream (used for debugging) Signed-off-by: Greg Balke <[email protected]> * Matching upstream changes Signed-off-by: Greg Balke <[email protected]> * Convert ActionClient to use C++ classes (#759) * Convert ActionClient to use C++ classes Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Added convert_from_py to utils Signed-off-by: ahcorde <[email protected]> * improved docs Signed-off-by: ahcorde <[email protected]> * nits to adapt the code to pybind11 Signed-off-by: ahcorde <[email protected]> * throw a exception in convert_from_py Signed-off-by: ahcorde <[email protected]> * Fixed docs Signed-off-by: ahcorde <[email protected]> * Convert ActionServer to use C++ Classes (#766) * Convert ActionServer to use C++ Classes Signed-off-by: ahcorde <[email protected]> * Fixed Test_action_server Signed-off-by: ahcorde <[email protected]> * Improved docs Signed-off-by: ahcorde <[email protected]> * Improved docs and minor fixes Signed-off-by: ahcorde <[email protected]> * Convert WaitSet to use C++ Classes (#769) * Convert WaitSet to use C++ Classes Signed-off-by: ahcorde <[email protected]> * added feedback Signed-off-by: ahcorde <[email protected]> * Removed unused structs (#770) Signed-off-by: ahcorde <[email protected]> * Convert Guardcondition to use C++ classes (#772) * Convert Guardcondition to use C++ classes Signed-off-by: ahcorde <[email protected]> * make destroy guard condition capsule function private Signed-off-by: ahcorde <[email protected]> * Pybind11 action goal handle nitpicks (#767) * Add GoalEvent back to module Signed-off-by: Shane Loretz <[email protected]> * self._goal -> self._goal_handle Signed-off-by: Shane Loretz <[email protected]> * Remove unused API Signed-off-by: Shane Loretz <[email protected]> Co-authored-by: ahcorde <[email protected]> * Pybind11 actionserver nitpicks and docblock improvements (#774) Signed-off-by: ahcorde <[email protected]> * Convert Node and Context to use C++ Classes (#771) * convert Node and Context to use C++ Classes Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Implement solution 1 Signed-off-by: ahcorde <[email protected]> * Prevent double early destruction of destroyable This along with an extra call to `destroy_node()` in `Node.__del__` was causing a segfault in the test_publisher test. The problem is `destroy_when_not_in_use()` was being called twice, and the second time is now a problem because rcl_ptrs_ is dereferenced in the qos_event destroy() method. Signed-off-by: Shane Loretz <[email protected]> * Remove unnecessary Node.__del__ This should not be required. If it is, it means there's a bug that shows when the Node is garbage collected. Signed-off-by: Shane Loretz <[email protected]> * Fix order of pointers in RclPtrs structs The order of the pointers in the RclPtrs structs is important. Things at the bottom are destroyed first, so children must be placed underneath the parent's that must be kept alive. Signed-off-by: Shane Loretz <[email protected]> * Intentionally copy rclpy:: objects instead of having RclPtrs structs (#773) * Rough pass converting everything Signed-off-by: Shane Loretz <[email protected]> * Fixes to get copy destruction order working Signed-off-by: Shane Loretz <[email protected]> * Fix qos_event test flakiness Signed-off-by: Shane Loretz <[email protected]> Signed-off-by: ahcorde <[email protected]> * MacOS warning Signed-off-by: ahcorde <[email protected]> * added feedback and removed some files Signed-off-by: ahcorde <[email protected]> * Create only one context otherwise throw a exception Signed-off-by: ahcorde <[email protected]> Co-authored-by: Shane Loretz <[email protected]> Co-authored-by: Shane Loretz <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]> Co-authored-by: Greg Balke <[email protected]> Co-authored-by: ahcorde <[email protected]>
* convert Node and Context to use C++ Classes Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Implement solution 1 Signed-off-by: ahcorde <[email protected]> * Prevent double early destruction of destroyable This along with an extra call to `destroy_node()` in `Node.__del__` was causing a segfault in the test_publisher test. The problem is `destroy_when_not_in_use()` was being called twice, and the second time is now a problem because rcl_ptrs_ is dereferenced in the qos_event destroy() method. Signed-off-by: Shane Loretz <[email protected]> * Remove unnecessary Node.__del__ This should not be required. If it is, it means there's a bug that shows when the Node is garbage collected. Signed-off-by: Shane Loretz <[email protected]> * Fix order of pointers in RclPtrs structs The order of the pointers in the RclPtrs structs is important. Things at the bottom are destroyed first, so children must be placed underneath the parent's that must be kept alive. Signed-off-by: Shane Loretz <[email protected]> * Intentionally copy rclpy:: objects instead of having RclPtrs structs (#773) * Rough pass converting everything Signed-off-by: Shane Loretz <[email protected]> * Fixes to get copy destruction order working Signed-off-by: Shane Loretz <[email protected]> * Fix qos_event test flakiness Signed-off-by: Shane Loretz <[email protected]> Signed-off-by: ahcorde <[email protected]> * MacOS warning Signed-off-by: ahcorde <[email protected]> * added feedback and removed some files Signed-off-by: ahcorde <[email protected]> * Create only one context otherwise throw a exception Signed-off-by: ahcorde <[email protected]> Co-authored-by: Shane Loretz <[email protected]> Co-authored-by: Shane Loretz <[email protected]>
* convert Node and Context to use C++ Classes Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Implement solution 1 Signed-off-by: ahcorde <[email protected]> * Prevent double early destruction of destroyable This along with an extra call to `destroy_node()` in `Node.__del__` was causing a segfault in the test_publisher test. The problem is `destroy_when_not_in_use()` was being called twice, and the second time is now a problem because rcl_ptrs_ is dereferenced in the qos_event destroy() method. Signed-off-by: Shane Loretz <[email protected]> * Remove unnecessary Node.__del__ This should not be required. If it is, it means there's a bug that shows when the Node is garbage collected. Signed-off-by: Shane Loretz <[email protected]> * Fix order of pointers in RclPtrs structs The order of the pointers in the RclPtrs structs is important. Things at the bottom are destroyed first, so children must be placed underneath the parent's that must be kept alive. Signed-off-by: Shane Loretz <[email protected]> * Intentionally copy rclpy:: objects instead of having RclPtrs structs (#773) * Rough pass converting everything Signed-off-by: Shane Loretz <[email protected]> * Fixes to get copy destruction order working Signed-off-by: Shane Loretz <[email protected]> * Fix qos_event test flakiness Signed-off-by: Shane Loretz <[email protected]> Signed-off-by: ahcorde <[email protected]> * MacOS warning Signed-off-by: ahcorde <[email protected]> * added feedback and removed some files Signed-off-by: ahcorde <[email protected]> * Create only one context otherwise throw a exception Signed-off-by: ahcorde <[email protected]> Co-authored-by: Shane Loretz <[email protected]> Co-authored-by: Shane Loretz <[email protected]> Signed-off-by: Shane Loretz <[email protected]>
* convert Node and Context to use C++ Classes Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Added feedback Signed-off-by: ahcorde <[email protected]> * Implement solution 1 Signed-off-by: ahcorde <[email protected]> * Prevent double early destruction of destroyable This along with an extra call to `destroy_node()` in `Node.__del__` was causing a segfault in the test_publisher test. The problem is `destroy_when_not_in_use()` was being called twice, and the second time is now a problem because rcl_ptrs_ is dereferenced in the qos_event destroy() method. Signed-off-by: Shane Loretz <[email protected]> * Remove unnecessary Node.__del__ This should not be required. If it is, it means there's a bug that shows when the Node is garbage collected. Signed-off-by: Shane Loretz <[email protected]> * Fix order of pointers in RclPtrs structs The order of the pointers in the RclPtrs structs is important. Things at the bottom are destroyed first, so children must be placed underneath the parent's that must be kept alive. Signed-off-by: Shane Loretz <[email protected]> * Intentionally copy rclpy:: objects instead of having RclPtrs structs (#773) * Rough pass converting everything Signed-off-by: Shane Loretz <[email protected]> * Fixes to get copy destruction order working Signed-off-by: Shane Loretz <[email protected]> * Fix qos_event test flakiness Signed-off-by: Shane Loretz <[email protected]> Signed-off-by: ahcorde <[email protected]> * MacOS warning Signed-off-by: ahcorde <[email protected]> * added feedback and removed some files Signed-off-by: ahcorde <[email protected]> * Create only one context otherwise throw a exception Signed-off-by: ahcorde <[email protected]> Co-authored-by: Shane Loretz <[email protected]> Co-authored-by: Shane Loretz <[email protected]> Signed-off-by: Shane Loretz <[email protected]>
Related to #665
This converts the Node and Context functions to a C++ class.
This PR depends on this other PR #728 and include the changes of this branch about GuardCondition to use C++ classes.
There is one test which is failing:
I will create this as a draft, we need to decide if we are going to backport the signal PR or find a workaround.