diff --git a/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/elementdata.py b/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/elementdata.py index 51fc0bc1..5ee546d3 100644 --- a/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/elementdata.py +++ b/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/elementdata.py @@ -28,6 +28,13 @@ class ElementData(object): Stores information created by a FlowElement based on FlowData. Stored in FlowData + Only the Flow Element that creates an instance writes it, so an instance + does not need to be safe to write from several threads. A finished + instance, once the Flow Element that writes it has finished, is safe to + read from several threads at once, such as the caller's own threads. An + instance that is written from several threads, or read while another + thread writes it, is not catered for. + """ def __init__(self, flow_element): diff --git a/pipeline/fiftyone_pipeline_core/tests/test_elementdata_documentation.py b/pipeline/fiftyone_pipeline_core/tests/test_elementdata_documentation.py new file mode 100644 index 00000000..58d88e28 --- /dev/null +++ b/pipeline/fiftyone_pipeline_core/tests/test_elementdata_documentation.py @@ -0,0 +1,26 @@ + +""" +The documentation of Element Data says it is safe to read from several threads +once the Flow Element that writes it has finished, and is not catered for when +written from several threads or read while another thread writes, as the +thread safety page of the specification requires. +""" + +import unittest + +from fiftyone_pipeline_core.elementdata import ElementData + + +class ElementDataDocumentationTests(unittest.TestCase): + + def test_the_documentation_says_what_is_safe_with_threads(self): + text = " ".join(ElementData.__doc__.split()) + self.assertIn("safe to read from several threads", text) + self.assertIn("once the Flow Element that writes it has finished", text) + self.assertIn("not catered for", text) + self.assertIn("written from several threads", text) + self.assertIn("read while another thread writes", text) + + +if __name__ == "__main__": + unittest.main()