Note
Even though these types are made for public consumption and usage should be encouraged/easily possible it should be noted that these may be moved out to new libraries at various points in the future. If you are using these types without using the rest of this library it is strongly encouraged that you be a vocal proponent of getting these made into isolated libraries (as using these types in this manner is not the expected and/or desired usage).
Bases: object
Entity object that identifies some resource/item/other.
Variables: |
|
---|
Bases: taskflow.utils.mixins.StrMixin
An immutable object that represents failure.
Failure objects encapsulate exception information so that they can be re-used later to re-raise, inspect, examine, log, print, serialize, deserialize...
One example where they are depended upon is in the WBE engine. When a remote worker throws an exception, the WBE based engine will receive that exception and desire to reraise it to the user/caller of the WBE based engine for appropriate handling (this matches the behavior of non-remote engines). To accomplish this a failure object (or a to_dict() form) would be sent over the WBE channel and the WBE based engine would deserialize it and use this objects reraise() method to cause an exception that contains similar/equivalent information as the original exception to be reraised, allowing the user (or the WBE engine itself) to then handle the worker failure/exception as they desire.
For those who are curious, here are a few reasons why the original exception itself may not be reraised and instead a reraised wrapped failure exception object will be instead. These explanations are only applicable when a failure object is serialized and deserialized (when it is retained inside the python process that the exception was created in the the original exception can be reraised correctly without issue).
TODO(harlowja): use parts of http://bugs.python.org/issue17911 and the backport at https://pypi.python.org/pypi/traceback2/ to (hopefully) simplify the methods and contents of this object...
Root exceptions of all other python exceptions.
Expected failure schema (in json schema format).
Checks if another object is equivalent to this object.
Returns: | checks if another object is equivalent to this object |
---|---|
Return type: | boolean |
Exception value, or none if exception value is not present.
Exception value may be lost during serialization.
Exception info tuple or none.
Re-raise exceptions if argument is not empty.
If argument is empty list/tuple/iterator, this method returns None. If argument is converted into a list with a single Failure object in it, that failure is reraised. Else, a WrappedFailure exception is raised with the failure list as causes.
Check if any of exc_classes caused the failure.
Arguments of this method can be exception types or type names (stings). If captured exception is instance of exception of given type, the corresponding argument is returned. Else, None is returned.
Tuple of all inner failure causes of this failure.
NOTE(harlowja): Does not include the current failure (only returns connected causes of this failure, if any). This property is really only useful on 3.x or newer versions of python as older versions do not have associated causes (the tuple will always be empty on 2.x versions of python).
Refer to PEP 3134 and PEP 409 and PEP 415 for what this is examining to find failure causes.
Bases: networkx.classes.graph.Graph
A graph subclass with useful utility functions.
Bases: networkx.classes.digraph.DiGraph
A directed graph subclass with useful utility functions.
Returns a copy of the edge attribute dictionary between (u, v).
NOTE(harlowja): this differs from the networkx get_edge_data() as that function does not return a copy (but returns a reference to the actual edge data).
Pretty formats your graph into a string.
This pretty formatted string representation includes many useful details about your graph, including; name, type, frozeness, node count, nodes, edge count, edges, graph density and graph cycles (if any).
Iterates breadth first over all predecessors of a given node.
This will go through the nodes predecessors, then the predecessor nodes predecessors and so on until no more predecessors are found.
NOTE(harlowja): predecessor cycles (if they exist) will not be iterated over more than once (this prevents infinite iteration).
Bases: taskflow.types.graph.DiGraph
A directed graph subclass with useful utility functions.
This derivative retains node, edge, insertion and iteration ordering (so that the iteration order matches the insertion order).
alias of OrderedDict
alias of OrderedDict
alias of OrderedDict
Bases: taskflow.types.graph.Graph
A graph subclass with useful utility functions.
This derivative retains node, edge, insertion and iteration ordering (so that the iteration order matches the insertion order).
alias of OrderedDict
alias of OrderedDict
alias of OrderedDict
Bases: object
Immutable helper that represents a notification listener/target.
Bases: object
A notification (pub/sub like) helper class.
It is intended to be used to subscribe to notifications of events occurring as well as allow a entity to post said notifications to any associated subscribers without having either entity care about how this notification occurs.
Not thread-safe when a single notifier is mutated at the same time by multiple threads. For example having multiple threads call into register() or reset() at the same time could potentially end badly. It is thread-safe when only notify() calls or other read-only actions (like calling into is_registered()) are occurring at the same time.
Keys that can not be used in callbacks arguments
Kleene star constant that is used to receive all notifications
Check if a callback is registered.
Returns: | checks if the callback is registered |
---|---|
Return type: | boolean |
Notify about event occurrence.
All callbacks registered to receive notifications about given event type will be called. If the provided event type can not be used to emit notifications (this is checked via the can_be_registered() method) then it will silently be dropped (notification failures are not allowed to cause or raise exceptions).
Parameters: |
|
---|
Register a callback to be called when event of a given type occurs.
Callback will be called with provided args and kwargs and when event type occurs (or on any event if event_type equals to ANY). It will also get additional keyword argument, details, that will hold event details provided to the notify() method (if a details filter callback is provided then the target callback will only be triggered if the details filter callback returns a truthy value).
Parameters: |
|
---|
Remove a single listener bound to event event_type.
Parameters: | event_type – deregister listener bound to event_type |
---|
Remove a group of listeners bound to event event_type.
Parameters: | event_type – deregister listeners bound to event_type |
---|
Bases: taskflow.types.notifier.Notifier
A notification class that restricts events registered/triggered.
NOTE(harlowja): This class unlike Notifier restricts and disallows registering callbacks for event types that are not declared when constructing the notifier.
Context manager that registers a callback, then deregisters on exit.
Bases: _abcoll.Set, _abcoll.Hashable
A read-only hashable set that retains insertion/initial ordering.
It should work in all existing places that frozenset is used.
See: https://mail.python.org/pipermail/python-ideas/2009-May/004567.html for an idea thread that may eventually (someday) result in this (or similar) code being included in the mainline python codebase (although the end result of that thread is somewhat discouraging in that regard).
Return the intersection of two or more sets as a new set.
(i.e. elements that are common to all of the sets.)
Bases: exceptions.Exception
Exception raised when a frozen node is modified.
Bases: object
A n-ary node class that can be used to create tree structures.
Default string used to horizontally connect a node to its parent (used in pformat().).
Default string used to vertically connect a node to its parent (used in pformat()).
Adds a child to this node (appends to left of existing children).
NOTE(harlowja): this will also set the childs parent to be this node.
Finds the first node that matching callback returns true.
This will search not only this node but also any children nodes (in depth first order, from right to left) and finally if nothing is matched then None is returned instead of a node object.
Parameters: |
|
---|---|
Returns: | the node that matched (or None) |
Returns the first node for an item if it exists in this node.
This will search not only this node but also any children nodes (in depth first order, from right to left) and finally if nothing is matched then None is returned instead of a node object.
Parameters: |
|
---|---|
Returns: | the node that matched provided item (or None) |
Removes this node from its parent (if any).
Returns: | occurrences of this node that were removed from its parent. |
---|
Removes a item from this nodes children.
This will search not only this node but also any children nodes and finally if nothing is found then a value error is raised instead of the normally returned removed node object.
Parameters: |
|
---|
Formats this node + children into a nice string representation.
Example:
>>> from taskflow.types import tree
>>> yahoo = tree.Node("CEO")
>>> yahoo.add(tree.Node("Infra"))
>>> yahoo[0].add(tree.Node("Boss"))
>>> yahoo[0][0].add(tree.Node("Me"))
>>> yahoo.add(tree.Node("Mobile"))
>>> yahoo.add(tree.Node("Mail"))
>>> print(yahoo.pformat())
CEO
|__Infra
| |__Boss
| |__Me
|__Mobile
|__Mail
Returns how many children this node has.
This can be either only the direct children of this node or inclusive of all children nodes of this node (children of children and so-on).
NOTE(harlowja): it does not account for the current node in this count.
Depth first iteration (non-recursive) over the child nodes.
Breadth first iteration (non-recursive) over the child nodes.
Converts this node + its children into a ordered directed graph.
The graph returned will have the same structure as the this node and its children (and tree node metadata will be translated into graph node metadata).
Returns: | a directed graph |
---|---|
Return type: | taskflow.types.graph.OrderedDiGraph |