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, and RobotAction.cancel() to request the action to stop (ie, it raises an ActionCancelled signal within the action thread). See RobotAction 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 signal ActionCancelled 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.FakeFuture(result)[source]

Used in the ‘immediate’ mode.

result()[source]
wait()[source]
class robots.concurrency.concurrency.RobotAction(actionname)[source]

Bases: concurrent.futures._base.Future

add_subaction(action)[source]
cancel()[source]
childof(action)[source]

Returns true if this action is a child of the given action, ie, has been spawned from the given action or any of its descendants.

result()[source]
set_parent(action)[source]
set_thread(thread)[source]
wait()[source]

alias for result()

class robots.concurrency.concurrency.RobotActionExecutor[source]
actioninfo(future_id)[source]
cancel_all()[source]

Blocks until all the currently running actions are actually stopped.

cancel_all_others()[source]

Blocks until all the currently running actions except the calling one are actually stopped.

get_current_action()[source]

Returns the RobotAction linked to the current thread.

submit(fn, *args, **kwargs)[source]
class robots.concurrency.concurrency.RobotActionThread(future, initialized, fn, args, kwargs)[source]

Bases: robots.concurrency.concurrency.SignalingThread

run()[source]
class robots.concurrency.concurrency.SignalingThread(*args, **kwargs)[source]

Bases: threading.Thread

cancel()[source]
pause()[source]

robots.concurrency.signals module

exception robots.concurrency.signals.ActionCancelled[source]

Bases: exceptions.UserWarning

exception robots.concurrency.signals.ActionPaused[source]

Bases: exceptions.UserWarning