Conversation
Adds Task and Future classes based on asyncio Callbacks can be coroutines, the executor runs them to completion
a0d88c8 to
d29fa97
Compare
If a task is executing, acquired its lock, but not set _executing = True yet and another thread calls the same task it is possible for the second thread to be blocked while the first thread executes. The intention is for the second thread to return immediately.
|
Oops, looks like the description I put on this task was completely wrong and from another PR. It's fixed now. |
|
@ros2/team Friendly ping. I would appreciate a review of this one. It is a prerequisite to multiple concurrent client requests (#170) and a |
dirk-thomas
left a comment
There was a problem hiding this comment.
The patch looks reasonable to me. I haven't tried to use the new API though.
| """ | ||
| Add a callback or coroutine to be executed during :meth:`spin` and return a Future. | ||
|
|
||
| Arguments to this function are passed to the callback. |
There was a problem hiding this comment.
Could this also permit keyword arguments?
There was a problem hiding this comment.
I didn't think about it before. It might be necessary to pass executor using a setter function instead to avoid a collision if the callback wants to use a keyword argument with that name.
There was a problem hiding this comment.
In 5f2cb1e the expansion of args and kwargs in Task.__init__() was removed to prevent that collision. The expansion on executor.create_task() cannot conflict because they're now passed to Task.__init__() as a sequence and dictionary.
|
Hi @sloretz! Is it possible/easy to make the equivalent of (We have been trying to find a robust pattern for waiting in the execute functions of action servers in rclpy. The only pattern that works for us 100% reliably so far is using a SingleThreadedExecutor and |
Removing unused helper function from tcpros.rs
This adds coroutine support to the executor and is part of service feature parity #123 and
wait_for_servicewithout aGraphListener#58.Any callback can now be a coroutine function (
async def). If the callback is a coroutine and it becomes blocked the executor will move on and resume executing it later. The details of this are handled in the classTaskwhich is a class very similar to asyncio.Task.asynciocan't be used directly because it is not thread safe.This PR also adds a
Futureclass that represents the result of a stored task. It is not used in this PR, but an example of using it is in #170.CI ( with 5f2cb1e)