exopy.tasks.tasks.base_tasks module

Definition of the base tasks.

The base tasks define how task interact between them and with the database, how ressources can be shared and how preferences are handled.

exopy.tasks.tasks.base_tasks.PREFIX = '_a'

Prefix for placeholders in string formatting and evaluation.

exopy.tasks.tasks.base_tasks.DEP_TYPE = 'exopy.task'

Id used to identify dependencies type.

class exopy.tasks.tasks.base_tasks.BaseTask[source]

Bases: atom.atom.Atom

Base class defining common members of all Tasks.

This class basically defines the minimal skeleton of a Task in term of members and methods.

Notes

A number of the member used by the task have a definite meaning only when a root is present. They are listed below:

  • depth

  • path

  • database

  • parent

dep_type

Identifier for the build dependency collector

task_id

Name of the class, used for persistence.

name

Name of the task this should be unique in hierarchy.

depth

Depth of the task in the hierarchy. this should not be manipulated directly by user code.

preferences

Reference to the Section in which the task stores its preferences.

database

Reference to the database used by the task to exchange information.

database_entries

Entries the task declares in the database and the associated default values. This should be copied and re-assign when modified not modfied in place.

path

Path of the task in the hierarchy. This refers to the parent task and is used when writing in the database.

root

Reference to the root task in the hierarchy.

parent

Refrence to the parent task.

perform_

Unbound method called when the task is asked to do its job. This is basically the perform method but wrapped with useful stuff such as interruption check or parallel, wait features.

stoppable

Flag indicating if this task can be stopped.

parallel

Dictionary indicating whether the task is executed in parallel (‘activated’ key) and which is pool it belongs to (‘pool’ key).

wait

Dictionary indicating whether the task should wait on any pool before performing its job. Three valid keys can be used : - ‘activated’ : a bool indicating whether or not to wait. - ‘wait’ : the list should then specify which pool should be waited. - ‘no_wait’ : the list should specify which pool not to wait on.

access_exs

Dict of access exception in the database. This should not be manipulated by user code.

perform()[source]

Main method of the task called when the measurement is performed.

check(*args, **kwargs)[source]

Check that everything is alright before starting a measurement.

By default tries to format all members tagged with ‘fmt’ and try to eval all members tagged with ‘feval’.

prepare()[source]

Prepare the task to be performed.

This method is called once by the root task before starting the execution of its children tasks. By default it simply build the perform_ method by wrapping perform with the appropriate decorators. This method can be overridden to execute other actions, however keep in my mind that those actions must not depende on the state of the system (no link to database).

register_preferences()[source]

Create the task entries in the preferences object.

update_preferences_from_members()[source]

Update the entries in the preference object.

classmethod build_from_config(config, dependencies)[source]

Create a new instance using the provided infos for initialisation.

Parameters
  • config (dict(str)) – Dictionary holding the new values to give to the members in string format, or dictionnary like for instance with prefs.

  • dependencies (dict) – Dictionary holding the necessary classes needed when rebuilding..

traverse(depth=- 1)[source]

Yield a task and all of its components.

The base implementation simply yields the task itself.

Parameters

depth (int) – How deep should we explore the tree of tasks. When this number reaches zero deeper children should not be explored but simply yielded.

register_in_database()[source]

Register the task entries into the database.

unregister_from_database()[source]

Remove the task entries from the database.

add_access_exception(entry, level)[source]

Add an access exception for an entry.

Parameters
  • entry (unicode) – Name of the task database entry for which to add an exception.

  • level (int) – Number of hierarchical levels to go up when adding the exception.

modify_access_exception(entry, new)[source]

Modify the level of an existing access exception.

Parameters
  • entry (unicode) – Name of the task database entry for which to modify an exception.

  • new (int) – New level for the access exception. If this is not strictly positive the access exception is simply removed.

remove_access_exception(entry)[source]

Remove an access exception .

Parameters

entry (unicode) – Name of the task database entry for which to remove an exception.

write_in_database(name, value)[source]

Write a value to the right database entry.

This method build a task specific database entry from the name and the name argument and set the database entry to the specified value.

Parameters
  • name (str) – Simple name of the entry whose value should be set, ie no task name required.

  • value – Value to give to the entry.

get_from_database(full_name)[source]

Access to a database value using full name.

Parameters

full_name (str) – Full name of the database entry, ie name + ‘_’ + entry, where name is the name of the task that wrote the value in the database.

remove_from_database(full_name)[source]

Delete a database entry using its full name.

Parameters

full_name (str) – Full name of the database entry, ie name + ‘_’ + entry, where name is the name of the task that wrote the value in the database.

list_accessible_database_entries()[source]

List the database entries accessible from this task.

format_string(string)[source]

Replace values between {} by their corresponding database value.

Parameters

string (str) – The string to format using the current values of the database.

Returns

formatted – Formatted version of the input.

Return type

str

format_and_eval_string(string)[source]

Replace values in {} by their corresponding database value and eval

Parameters

string (str) – The string to eval using the current values of the database.

Returns

value – Evaluated version of the input.

Return type

object

get_error_path()[source]

Build the path to use when reporting errors during checks.

class exopy.tasks.tasks.base_tasks.SimpleTask[source]

Bases: exopy.tasks.tasks.base_tasks.BaseTask

Task with no child task, written in pure Python.

This class is mainly used to avoid having a linear ancestry relationship between SimpleTask and ComplexTask.

loopable = False

Class attribute specifying if that task can be used in a loop

register_preferences()[source]

Register the task preferences into the preferences system.

update_preferences_from_members()

Register the task preferences into the preferences system.

classmethod build_from_config(config, dependencies)[source]

Create a new instance using the provided infos for initialisation.

Parameters
  • config (dict(str)) – Dictionary holding the new values to give to the members in string format, or dictionnary like for instance with prefs.

  • dependencies (dict) – Dictionary holding the necessary classes needed when rebuilding.

class exopy.tasks.tasks.base_tasks.ComplexTask[source]

Bases: exopy.tasks.tasks.base_tasks.BaseTask

Task composed of several subtasks.

children

List of all the children of the task. The list should not be manipulated directly by user code. The tag ‘child’ is used to mark that a member can contain child tasks and is used to gather children for operation which must occur on all of them.

children_changed

Signal emitted when the list of children change, the payload will be a ContainerChange instance. The tag ‘child_notifier’ is used to mark that a member emmit notifications about modification of another ‘child’ member. This allow editors to correctly track all of those.

perform()[source]

Run sequentially all child tasks.

check(*args, **kwargs)[source]

Run test of all child tasks.

prepare()[source]

Overridden to prepare also children tasks.

add_child_task(index, child)[source]

Add a child task at the given index.

Parameters
  • index (int) – Index at which to insert the new child task.

  • child (BaseTask) – Task to insert in the list of children task.

move_child_task(old, new)[source]

Move a child task.

Parameters
  • old (int) – Index at which the child to move is currently located.

  • new (BaseTask) – Index at which to insert the child task.

remove_child_task(index)[source]

Remove a child task from the children list.

Parameters

index (int) – Index at which the child to remove is located.

gather_children()[source]

Build a flat list of all children task.

Children tasks are ordered according to their ‘child’ tag value.

Returns

children – List of all the task children.

Return type

list

traverse(depth=- 1)[source]

Reimplemented to yield all child task.

register_in_database()[source]

Create a node in the database and register all entries.

This method registers both the task entries and all the tasks tagged as child.

unregister_from_database()[source]

Unregister all entries and delete associated database node.

This method unregisters both the task entries and all the tasks tagged as child.

register_preferences()[source]

Register the task preferences into the preferences system.

This method registers both the task preferences and all the preferences of the tasks tagged as child.

update_preferences_from_members()[source]

Update the values stored in the preference system.

This method updates both the task preferences and all the preferences of the tasks tagged as child.

classmethod build_from_config(config, dependencies)[source]

Create a new instance using the provided infos for initialisation.

Parameters
  • config (dict(str)) – Dictionary holding the new values to give to the members in string format, or dictionnary like for instance with prefs.

  • dependencies (dict) – Dictionary holding the necessary classes needed when rebuilding. This is assembled by the TaskManager.

Returns

task – Newly created and initiliazed task.

Return type

BaseTask

Notes

This method is fairly powerful and can handle a lot of cases so don’t override it without checking that it works.

name

A value of type str.

Under Python 2 this is a byte string and behaves as Bytes with respect to promotion, under Python 3 it is a unicode string and behaves as Unicode with respect to promotion.

The use of this member is discouraged in Python 2/3 compatible codebase as Bytes and Unicode provide a more homogeneous behavior.

root

A Typed which delays resolving the type definition.

The first time the value is accessed or modified, the type will be resolved and the forward typed will behave identically to a normal typed.

class exopy.tasks.tasks.base_tasks.RootTask(*args, **kwargs)[source]

Bases: exopy.tasks.tasks.base_tasks.ComplexTask

Special task which is always the root of a measurement.

On this class and this class only perform can and should be called directly.

default_path

Path to which log infos, preferences, etc should be written by default.

should_profile

Should the execution be profiled.

run_time

drivers classes)

Type

Dict storing data needed at execution time (ex

should_stop

Inter-process event signaling the task it should stop execution.

should_pause

Inter-process event signaling the task it should pause execution.

paused

Inter-process event signaling the task is paused.

resumed

Inter-process event signaling the main thread is done, handling the measurement resuming, and hence notifying the task execution has resumed.

errors

Dictionary used to store errors occuring during performing.

resources

Dictionary used to store references to resources that may need to be shared between task and which must be released when all tasks have been performed. Each key is associated to a different kind of resource. Resources must be stored in SharedDict subclass. By default three kind of resources exists:

  • threads : used threads grouped by pool.

  • active_threads : currently active threads.

  • instrs : used instruments referenced by profiles.

  • files : currently opened files by path.

active_threads_counter

Counter keeping track of the active threads.

paused_threads_counter

Counter keeping track of the paused threads.

thread_id

Thread from which the perform method has been called.

name

A value which cannot be changed from its default.

depth

A value which cannot be changed from its default.

path

A value which cannot be changed from its default.

database_entries

A value of type dict.

check(*args, **kwargs)[source]

Check that the default path is a valid directory.

perform()[source]

Run sequentially all child tasks, and close ressources.

prepare()[source]

Optimise the database for running state and prepare children.

release_resources()[source]

Release all the resources used by tasks.

register_in_database()[source]

Don’t create a node for the root task.

classmethod build_from_config(config, dependencies)[source]

Create a new instance using the provided infos for initialisation.

Parameters
  • config (dict(str)) – Dictionary holding the new values to give to the members in string format, or dictionnary like for instance with prefs.

  • dependencies (dict) – Dictionary holding the necessary classes needed when rebuilding. This is assembled by the TaskManager.

Returns

task – Newly created and initiliazed task.

Return type

RootTask

Notes

This method is fairly powerful and can handle a lot of cases so don’t override it without checking that it works.

get_used_names()[source]

Return the list of all names used in the tree :returns: names – List of all the names used in the tree. :rtype: List(str)

task_id

A value of type str.

Under Python 2 this is a byte string and behaves as Bytes with respect to promotion, under Python 3 it is a unicode string and behaves as Unicode with respect to promotion.

The use of this member is discouraged in Python 2/3 compatible codebase as Bytes and Unicode provide a more homogeneous behavior.