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.
-
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.
-
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).
-
classmethod
build_from_config
(config, dependencies)[source]¶ Create a new instance using the provided infos for initialisation.
-
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.
-
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.
-
-
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
-
update_preferences_from_members
()¶ Register the task preferences into the preferences system.
-
-
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.
-
has_root
¶ Flag indicating whether or not the task has a root 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
-
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
- Returns
task – Newly created and initiliazed task.
- Return type
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 unicode.
By default, plain strings will be promoted to unicode strings. Pass strict=True to the constructor to enable strict unicode checking.
-
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.
-
has_root
¶ A value of type bool.
-
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.
-
classmethod
build_from_config
(config, dependencies)[source]¶ Create a new instance using the provided infos for initialisation.
- Parameters
- Returns
task – Newly created and initiliazed task.
- Return type
Notes
This method is fairly powerful and can handle a lot of cases so don’t override it without checking that it works.
-
task_id
¶ A value of type unicode.
By default, plain strings will be promoted to unicode strings. Pass strict=True to the constructor to enable strict unicode checking.
-