Skip to content

Commit

Permalink
Ensure only 1 thread loads all the wrapper cls
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Apr 10, 2024
1 parent 5307f52 commit 90ea666
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions py/server/deephaven/_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import inspect
import pkgutil
import sys
import threading
from abc import ABC, abstractmethod
from typing import Set, Union, Optional, Any, List

Expand All @@ -23,6 +24,7 @@

JLivePyObjectWrapper = jpy.get_type('io.deephaven.server.plugin.python.LivePyObjectWrapper')

_recursive_import_lock = threading.Lock()

def _recursive_import(package_path: str) -> None:
""" Recursively import every module in a package. """
Expand Down Expand Up @@ -107,9 +109,10 @@ def _lookup_wrapped_class(j_obj: jpy.JType) -> List[JObjectWrapper]:
# load every module in the deephaven package so that all the wrapper classes are loaded and available to wrap
# the Java objects returned by calling resolve()
global _has_all_wrappers_imported
if not _has_all_wrappers_imported:
_recursive_import(__package__.partition(".")[0])
_has_all_wrappers_imported = True
with _recursive_import_lock:
if not _has_all_wrappers_imported:
_recursive_import(__package__.partition(".")[0])
_has_all_wrappers_imported = True

return [wc for wc in _di_wrapper_classes if wc.j_object_type.jclass.isInstance(j_obj)]

Expand Down

0 comments on commit 90ea666

Please sign in to comment.