[misc][plugin] improve plugin loading (#10443)

Signed-off-by: youkaichao <youkaichao@gmail.com>
This commit is contained in:
youkaichao 2024-11-19 02:43:21 -08:00 committed by GitHub
parent 5390d6664f
commit 25f9c78961
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,12 +9,19 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__)
# make sure one process only loads plugins once
plugins_loaded = False
def load_general_plugins():
"""WARNING: plugins can be loaded for multiple times in different
processes. They should be designed in a way that they can be loaded
multiple times without causing issues.
"""
global plugins_loaded
if plugins_loaded:
return
plugins_loaded = True
import sys
if sys.version_info < (3, 10):
from importlib_metadata import entry_points