diff --git a/docs/source/user_guide/config.rst b/docs/source/user_guide/config.rst index 0a63a31214..a4fdbe514f 100644 --- a/docs/source/user_guide/config.rst +++ b/docs/source/user_guide/config.rst @@ -130,6 +130,10 @@ FiftyOne supports the configuration options described below: | | | | operations such reading/writing large datasets or activiating FiftyOne | | | | | Brain methods on datasets. | +-------------------------------+-------------------------------------+-------------------------------+----------------------------------------------------------------------------------------+ +| `singleton_cache` | `FIFTYONE_SINGLETON_CACHE` | `True` | Whether to treat :class:`Dataset `, | +| | | | :class:`Sample `, and | +| | | | :class:`Frame ` instances as singletons. | ++-------------------------------+-------------------------------------+-------------------------------+----------------------------------------------------------------------------------------+ | `timezone` | `FIFTYONE_TIMEZONE` | `None` | An optional timzone string. If provided, all datetimes read from FiftyOne datasets | | | | | will be expressed in this timezone. See :ref:`this section ` for | | | | | more information. | @@ -191,6 +195,7 @@ and the CLI: "plugins_dir": null, "requirement_error_level": 0, "show_progress_bars": true, + "singleton_cache": true, "timezone": null } @@ -242,6 +247,7 @@ and the CLI: "plugins_dir": null, "requirement_error_level": 0, "show_progress_bars": true, + "singleton_cache": true, "timezone": null } diff --git a/fiftyone/core/config.py b/fiftyone/core/config.py index 32b5529775..5781bffe1d 100644 --- a/fiftyone/core/config.py +++ b/fiftyone/core/config.py @@ -260,6 +260,12 @@ def __init__(self, d=None): env_var="FIFTYONE_MAX_PROCESS_POOL_WORKERS", default=None, ) + self.singleton_cache = self.parse_bool( + d, + "singleton_cache", + env_var="FIFTYONE_SINGLETON_CACHE", + default=True, + ) self._init() diff --git a/fiftyone/core/singletons.py b/fiftyone/core/singletons.py index 78b7d8f1da..5012579aa9 100644 --- a/fiftyone/core/singletons.py +++ b/fiftyone/core/singletons.py @@ -8,6 +8,8 @@ from collections import defaultdict import weakref +import fiftyone as fo + class DatasetSingleton(type): """Singleton metaclass for :class:`fiftyone.core.dataset.Dataset`. @@ -44,7 +46,8 @@ def __call__(cls, name=None, _create=True, *args, **kwargs): name=name, _create=_create, *args, **kwargs ) - cls._instances[name] = instance + if fo.config.singleton_cache: + cls._instances[name] = instance return instance @@ -107,7 +110,8 @@ def __new__(metacls, *args, **kwargs): return cls def _register_instance(cls, obj): - cls._instances[obj._doc.collection_name][obj.id] = obj + if fo.config.singleton_cache: + cls._instances[obj._doc.collection_name][obj.id] = obj def _get_instance(cls, doc): try: @@ -248,9 +252,10 @@ def __new__(metacls, *args, **kwargs): return cls def _register_instance(cls, obj): - cls._instances[obj._doc.collection_name][obj.sample_id][ - obj.frame_number - ] = obj + if fo.config.singleton_cache: + cls._instances[obj._doc.collection_name][obj.sample_id][ + obj.frame_number + ] = obj def _get_instance(cls, doc): try: