Package ClusterShell :: Module Task :: Class Task
[hide private]
[frames] | no frames]

Class Task

source code



Task to execute. May be bound to a specific thread.

To create a task in a new thread:
    task = Task()

To create or get the instance of the task associated with the thread
identifier tid:
    task = Task(thread_id=tid)

Add command to execute locally in task with:
    task.shell("/bin/hostname")

Add command to execute in a distant node in task with:
    task.shell("/bin/hostname", nodes="tiger[1-20]")

Run task in its associated thread (will block only if the calling
thread is the associated thread:
    task.resume()

Instance Methods [hide private]
 
__init__(self, thread_id=None)
Initialize a Task, creating a new thread if needed.
source code
 
_start_thread(self)
New Task thread entry point.
source code
 
info(self, info_key, def_val=None)
Return per-task information.
source code
 
set_info(self, info_key, value)
Set task-specific information state.
source code
 
shell(self, command, **kwargs)
Schedule a shell command for local or distant execution.
source code
 
copy(self, source, dest, nodes, **kwargs)
Copy local file to distant nodes.
source code
 
timer(self, fire, handler, interval=-1.0, autoclose=False)
Create task's timer.
source code
 
schedule(self, worker)
Schedule a worker for execution.
source code
 
resume(self, timeout=0)
Resume task.
source code
 
abort(self, kill=False)
Abort a task.
source code
 
_terminate(self, kill)
Abort completion subroutine.
source code
 
join(self)
Suspend execution of the calling thread until the target task terminates, unless the target task has already terminated.
source code
 
_reset(self)
Reset buffers and retcodes management variables.
source code
 
_msg_add(self, source, msg)
Add a worker message associated with a source.
source code
 
_rc_set(self, source, rc, override=True)
Add a worker return code associated with a source.
source code
 
_timeout_add(self, source)
Add a worker timeout associated with a source.
source code
 
_msg_by_source(self, source)
Get a message by its source (worker, key).
source code
 
_msg_iter_by_key(self, key)
Return an iterator over stored messages for the given key.
source code
 
_msg_iter_by_worker(self, worker, match_keys=None)
Return an iterator over messages and keys list for a specific worker and optional matching keys.
source code
 
_kmsg_iter_by_worker(self, worker)
Return an iterator over key, message for a specific worker.
source code
 
_rc_by_source(self, source)
Get a return code by its source (worker, key).
source code
 
_rc_iter_by_key(self, key)
Return an iterator over return codes for the given key.
source code
 
_rc_iter_by_worker(self, worker, match_keys=None)
Return an iterator over return codes and keys list for a specific worker and optional matching keys.
source code
 
_krc_iter_by_worker(self, worker)
Return an iterator over key, rc for a specific worker.
source code
 
_num_timeout_by_worker(self, worker)
Return the number of timed out "keys" for a specific worker.
source code
 
_iter_keys_timeout_by_worker(self, worker)
Iterate over timed out keys (ie.
source code
 
key_buffer(self, key)
Get buffer for a specific key.
source code
 
node_buffer(self, key)
Get buffer for a specific key.
source code
 
key_retcode(self, key)
Return return code for a specific key.
source code
 
node_retcode(self, key)
Return return code for a specific key.
source code
 
max_retcode(self)
Get max return code encountered during last run.
source code
 
iter_buffers(self, match_keys=None)
Iterate over buffers, returns a tuple (buffer, keys).
source code
 
iter_retcodes(self, match_keys=None)
Iterate over return codes, returns a tuple (rc, keys).
source code
 
num_timeout(self)
Return the number of timed out "keys" (ie.
source code
 
iter_keys_timeout(self)
Iterate over timed out keys (ie.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
wait(cls, from_thread_id)
Class method that blocks calling thread until all tasks have finished.
source code
Static Methods [hide private]
a new object with type S, a subtype of T
__new__(cls, thread_id=None)
For task bound to a specific thread, this class acts like a "thread singleton", so new style class is used and new object are only instantiated if needed.
source code
Class Variables [hide private]
  _default_info = {'command_timeout': 0, 'connect_timeout': 10, ...
  _tasks = {}
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(cls, thread_id=None)
Static Method

source code 

For task bound to a specific thread, this class acts like a "thread singleton", so new style class is used and new object are only instantiated if needed.

Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__init__(self, thread_id=None)
(Constructor)

source code 

Initialize a Task, creating a new thread if needed.

Overrides: object.__init__

shell(self, command, **kwargs)

source code 

Schedule a shell command for local or distant execution.

Local usage:
    task.shell(command [, key=key] [, handler=handler]
            [, timeout=secs])

Distant usage:
    task.shell(command, nodes=nodeset [, handler=handler]
            [, timeout=secs])

schedule(self, worker)

source code 

Schedule a worker for execution. Only useful for manually instantiated workers.

resume(self, timeout=0)

source code 

Resume task. If task is task_self(), workers are executed in the calling thread so this method will block until workers have finished. This is always the case for a single-threaded application (eg. which doesn't create other Task() instance than task_self()). Otherwise, the current thread doesn't block. In that case, you may then want to call task_wait() to wait for completion.

abort(self, kill=False)

source code 

Abort a task. Aborting a task removes (and stops when needed) all workers. If optional parameter kill is True, the task object is unbound from the current thread, so calling task_self() creates a new Task object.

_iter_keys_timeout_by_worker(self, worker)

source code 

Iterate over timed out keys (ie. nodes) for a specific worker.

key_buffer(self, key)

source code 

Get buffer for a specific key. When the key is associated to multiple workers, the resulting buffer will contain all workers content that may overlap.

node_buffer(self, key)

source code 

Get buffer for a specific key. When the key is associated to multiple workers, the resulting buffer will contain all workers content that may overlap.

key_retcode(self, key)

source code 

Return return code for a specific key. When the key is associated to multiple workers, return the max return code from these workers.

node_retcode(self, key)

source code 

Return return code for a specific key. When the key is associated to multiple workers, return the max return code from these workers.

max_retcode(self)

source code 

Get max return code encountered during last run.

How retcodes work:
  If the process exits normally, the return code is its exit
  status. If the process is terminated by a signal, the return
  code is 128 + signal number.

iter_buffers(self, match_keys=None)

source code 

Iterate over buffers, returns a tuple (buffer, keys). For remote
workers (Ssh), keys are list of nodes. In that case, you should use
NodeSet.fromlist(keys) to get a NodeSet instance (which is more
convenient and efficient):

Optional parameter match_keys add filtering on these keys.

Usage example:

    for buffer, nodelist in task.iter_buffers():
        print NodeSet.fromlist(nodelist)
        print buffer

iter_retcodes(self, match_keys=None)

source code 

Iterate over return codes, returns a tuple (rc, keys).

Optional parameter match_keys add filtering on these keys.

How retcodes work:
  If the process exits normally, the return code is its exit
  status. If the process is terminated by a signal, the return
  code is 128 + signal number.

num_timeout(self)

source code 

Return the number of timed out "keys" (ie. nodes).

iter_keys_timeout(self)

source code 

Iterate over timed out keys (ie. nodes).


Class Variable Details [hide private]

_default_info

Value:
{'command_timeout': 0,
 'connect_timeout': 10,
 'debug': False,
 'fanout': 32,
 'print_debug': <function _task_print_debug at 0x13a5c80>}