pynbody.dependencytracker.DependencyTracker#
- class pynbody.dependencytracker.DependencyTracker[source]#
Bases:
object
Class for tracking dependencies between arrays.
This class is used by
pynbody.snapshot.simsnap.SimSnap
to track how derived arrays depend on other arrays. Users should not need to use this class directly.As an example of how this class is used, see the following code.
>>> my_tracker = DependencyTracker() >>> with my_tracker.calculating('my_array'): >>> with my_tracker.calculating('my_other_array'): >>> my_tracker.touching('source_array') >>> my_tracker.get_dependents('my_array') # -> {} >>> my_tracker.get_dependents('my_other_array') # -> {'my_array'} >>> my_tracker.get_dependents('source_array') # -> {'my_other_array', 'my_array'} >>> with my_tracker.calculating('my_array'): >>> with my_tracker.calculating('my_array'): # -> raises DependencyError >>> pass
Note that the class is thread-safe, in the sense that if a second thread starts trying to use it while a first thread is already mid-way through a derivation, the second thread blocks until the first thread finishes.
Methods
calculating
(name)Return a context manager when calculating a named array.
get_dependents
(name)Return the set of arrays that are known to depend on the named array.
touching
(name)Note that any ongoing calculations depend on the named array.