add global lock for ensure_colormap function
import os
+from threading import Lock
from typing import Dict, List, Tuple, Union
import numpy as np
@@ -346,6 +347,8 @@ ALL_COLORMAPS.update(BOP_COLORMAPS)
# ... sorted alphabetically by name
AVAILABLE_COLORMAPS = {k: v for k, v in sorted(ALL_COLORMAPS.items())}
+# lock to allow update of AVAILABLE_COLORMAPS in threads
+AVAILABLE_COLORMAPS_LOCK = Lock()
# curated colormap sets
# these are selected to look good or at least reasonable when using additive
@@ -406,10 +409,13 @@ def ensure_colormap(colormap: ValidColormapArg) -> Colormap:
TypeError
If ``colormap`` is not a ``str``, ``dict``, ``tuple``, or ``Colormap``
"""
+ with AVAILABLE_COLORMAPS_LOCK:
if isinstance(colormap, str):
name = colormap
if name not in AVAILABLE_COLORMAPS:
- cmap = vispy_or_mpl_colormap(name) # raises KeyError if not found
+ cmap = vispy_or_mpl_colormap(
+ name
+ ) # raises KeyError if not found
AVAILABLE_COLORMAPS[name] = cmap
elif isinstance(colormap, Colormap):
AVAILABLE_COLORMAPS[colormap.name] = colormap
