robots.concurrency package¶
robots.concurrency.action module¶
-
robots.concurrency.action.
action
(fn)[source]¶ When applied to a function, this decorator turns it into a asynchronous task, starts it in a different thread, and returns a ‘future’ object that can be used to query the result/cancel it/etc.
The main methods available on these ‘future’ object include
RobotAction.wait()
to wait until the action completes, andRobotAction.cancel()
to request the action to stop (ie, it raises anActionCancelled
signal within the action thread). SeeRobotAction
for the full list of available methods.Action implementation may want to handle the
ActionCancelled
signal to properly process cancellation requests.Usage example:
@action def safe_walk(robot): try: robot.walk() except ActionCancelled: robot.go_back_to_rest_pose() action = robot.safe_walk() time.sleep(1) action.cancel()
In this example, after one second, the
safe_walk
action is cancelled. This sends the signalActionCancelled
to the action, that can appropriately terminate.
robots.concurrency.concurrency module¶
Concurrency support for pyRobot.
This module provides:
- an implementation of
SignalingThread
(threads that explicitely handle signals like cancelation) - heavily modified Python futures to support robot action management.
- A future executor that simply spawn one thread per future (action) instead of a thread pool.
These objects should not be directly used. Users should instead rely on the
action()
decorator.
Helpful debugging commands:
>>> sys._current_frames()
>>> inspect.getouterframes(sys._current_frames()[<id>])[0][0].f_locals
-
class
robots.concurrency.concurrency.
RobotAction
(actionname)[source]¶ Bases:
concurrent.futures._base.Future
-
class
robots.concurrency.concurrency.
RobotActionExecutor
[source]¶