* Update test_node types
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* don't attempt to use typevar defaults
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
---------
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Signed-off-by: Jean Paul Sierra Boom <jeanpaulsierraboom@gmail.com>
Signed-off-by: Jean Paul <88939729+JeanPaulSB@users.noreply.github.com>
Co-authored-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
* Introduce EventsExecutor implementation (#1389)
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Fix explosion for reference count updates without GIL
The previous version worked on 22.04+Iron, but fails on 24.04+Jazzy or Rolling. It
seems like the behavior of std::bind() may have changed when asked to bind a py::object
to a callback taking a py::handle.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Fix ament linter complaints
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Switch to non-boost asio library
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Use internal _rclpy C++ types instead of jumping through Python hoops
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Reformat with clang-format, then uncrustify again
clang-format fixes things that uncrustify tends to leave alone, but then uncrustify seems slightly
unhappy with that result. Also reflow comments at 100 columns.
This uses the .clang-format file from the ament-clang-format package, with the exception of
SortIncludes being set to false, because I didn't like what it tried to do with includes without
that override.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Respect init signal handling options
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Reconcile signal handling differences with SingleThreadedExecutor
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* test_executor.py: Add coverage for EventsExecutor
Tests that currently work are enabled, and those that don't are annotated what needs to be done before they can be enabled
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Make spin_once() only return after a user-visible callback
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Add get_nodes() method
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Add context management support
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Remove mutex protection on nodes_ member access
It was being used only inconsistently, and on reflection it wasn't adding any protection beyond what
the GIL already provides.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Fix deadlock during shutdown()
Needed to release the GIL while blocking on another lock.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* A little further on using C++ _rclpy types instead of Python interface
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Fix issue with iterating through incomplete Tasks
Never bool-test a py::object::attr() return value without an explicit py::cast<bool>.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Add support for coroutines to timer handling
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Fix test_not_lose_callback() test to destroy entities properly
EventsExecutor was exploding because the test was leaving destroyed entities in the node by using an
incorrect API to destroy them.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Correct test that wasn't running at all, and remove EventsExecutor from it
* Test methods need to be prefixed with 'test_' in order to function. This had been entirely dead
code, and when I enabled it EventsExecutor deadlocked.
* On reflection, it seems like a deadlock is exactly what should be expected from what this test is
doing. Remove EventsExecutor from the test and document the problem.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Warn on every timer added over the threshold, not just the first
Co-authored-by: Janosch Machowinski <jmachowinski@users.noreply.github.com>
Signed-off-by: Brad Martin <52003535+bmartin427@users.noreply.github.com>
* Keep rcl_timer_call() tightly coupled with user callback dispatch
This both prevents an issue where user callbacks could potentially queue up if they didn't dispatch
fast enough, and ensures that a timer that has passed its expiration without being dispatched yet
can still be canceled without the user callback being delivered later.
This commit also makes use of the new rcl API for querying the absolute timer expiration time,
instead of the relative number of nanoseconds remaining until it expires. This should both make
things more accurate, and potentially reduce overhead as we don't have to re-query the current time
for each outstanding timer.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Protect against deferred method calls happening against a deleted ClockManager
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Add support for new TimerInfo data passed to timer handlers
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Simplify spin_once() implementation
This both reduces duplicate code now, and simplifies the asio interface used which would need
replacing.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Fix stale Future done callbacks with spin_until_future_complete()
This method can't be allowed to leave its Future done callback outstanding in case the method is
returning for a reason other than the Future being done.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Use existing rclpy signal handling instead of asio
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Replace asio timers with a dedicated timer wait thread
This is dumb on its own, but it helps me move towards eliminating asio.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Correct busy-looping in async callback handling
This isn't ideal because there are some ways async callbacks could become unblocked which wouldn't
get noticed right away (if at all); however this seems to match the behavior of
SingleThreadedExecutor.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Replace asio::io_context with a new EventsQueue object
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Add EventsExecutor to new test_executor test from merge
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Swap 'pragma once' for ifndef include guards
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Add test coverage for Node.destroy_subscription()
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Replace '|' type markup with typing.Optional and typing.Union
Python 3.9, still used by RHEL 9, doesn't seem to understand '|' syntax, and
Optional/Union seems to be what gets used throughout the rest of the codebase.
Additionally, fix a couple other mypy nits:
* mypy is mad that I haven't explicitly annotated every __init__ as returning None
* mypy wants generic arguments to service and action clients now
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Use 'auto' in place of explicit return type on hash
pybind11::hash() is documented as returning ssize_t, but this seems to be a lie because MSVC
doesn't understand that type; so, let's just return whatever we do get.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Change initialization of struct members
MSVC didn't like the more concise method.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Use subTest in test_executor to distinguish which executor type failed
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
* Use time.perf_counter() instead of time.monotonic() in executor test
time.monotonic() has a resolution of 16ms, which is way too coarse for the intervals
this test is trying to measure.
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
---------
Signed-off-by: Brad Martin <bmartin@fatlxception.org>
Signed-off-by: Brad Martin <52003535+bmartin427@users.noreply.github.com>
Co-authored-by: Brad Martin <bmartin@fatlxception.org>
Co-authored-by: Janosch Machowinski <jmachowinski@users.noreply.github.com>
* Add new interfaces to enable intropsection for action
Signed-off-by: Barry Xu <barry.xu@sony.com>
* Address review comments
Signed-off-by: Barry Xu <barry.xu@sony.com>
---------
Signed-off-by: Barry Xu <barry.xu@sony.com>
* init
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Various fixes
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* update parameter_event_handler
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add back EventMessage
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Move import of TypeAlias
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
---------
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
When the module is compiled with `MODULE` (the default), the proper linker flags are added on macOS (specifically `-undefined dynamic_lookup`). Otherwise, `rclpy` segfaults when linked on conda.
Is the `SHARED` really necessary? The `pybind11` documentation says:
> Specifying `SHARED` will create a more traditional dynamic library which can also be linked from elsewhere.
Signed-off-by: Wolf Vollprecht <w.vollprecht@gmail.com>
* Various typing fixes
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Parameter narrowing in node.py
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Update tuple[None, None] narrowing in actio clients and services
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Flake8 fixes in service_instrospection.pyi
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
---------
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add types to Action objects
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* fix inheritance order
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move type into string
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* string around type
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* missed string type
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* switch to 2 arg generics for clients/services
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move import into TYPE_CHECKING block
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Type over type
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add ClassVar
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Hopefully fix rhel failure
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run CI
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run CI
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Fix import
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Delete .vscode/settings.json
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Update client.py
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
---------
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Add types to wait_for_message.py
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add copyright
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run CI
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run CI
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move Handles into _rclpy_pybind11
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Move Handles into type stubs:
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Move Handles into type stubs
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move [] into string
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* fix imports
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* remove extra line
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* puy _rclpy.Publisher in quotes
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* fix capitalization
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add EventHandle Constructor
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Use RuntimeError for context
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add TYPE_CHECKING import
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* init
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* stash
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* more progress
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* done
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move type into string
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* rclpy.impl
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* spelling error and type in string
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* type in string
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Narrow Task[] type
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* remove if statements around nodes_to_use
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Change Generic Srv/Cli
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Update rclpy/rclpy/executors.py
Co-authored-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* EntityT cleanup
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Fix Optional goof
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* remove SrvEventT
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Only 2 args for srv/client
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* fix Callable[]
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
---------
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
* Add types to wait_for_message.py
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add copyright
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run CI
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run CI
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move Handles into _rclpy_pybind11
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Move Handles into type stubs:
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Move Handles into type stubs
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move [] into string
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* fix imports
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* remove extra line
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* puy _rclpy.Publisher in quotes
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* fix capitalization
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add EventHandle Constructor
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Use RuntimeError for context
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Add TYPE_CHECKING import
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* init
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* remove .vscode file
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* move into string
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* fix flake8
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
---------
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Add support for operator overloading of `Duration`
This PR adds support for operator overloading of the `Duration` class in
python. This should improve the overall UX of the rclpy library.
---------
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
* Init types
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* add typealias
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run ci
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run ci
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run ci
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* re-run ci
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
---------
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
* Client:call generates TimeoutError exception when it is timed out.
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
* call Thread.is_alive() to make sure the thread has started.
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
---------
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
* Fix the race condition while calling rcl_shutdown
Signed-off-by: Barry Xu <barry.xu@sony.com>
* Avoid calling rcl_shutdown() multiple times on the same context
Signed-off-by: Barry Xu <barry.xu@sony.com>
* Multiple calls to Context::shutdown will throw an exception
Signed-off-by: Barry Xu <barry.xu@sony.com>
* Update the name of an exception
Signed-off-by: Barry Xu <barry.xu@sony.com>
---------
Signed-off-by: Barry Xu <barry.xu@sony.com>