Fixed main thread closure issue caused by async.run
This commit is contained in:
@@ -3,7 +3,8 @@ import os
|
||||
import sys
|
||||
import importlib
|
||||
import traceback
|
||||
import asyncio
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from os.path import join
|
||||
from os.path import isdir
|
||||
|
||||
@@ -76,13 +77,10 @@ class PluginsController(ControllerBase, PluginsControllerMixin, PluginReloadMixi
|
||||
module = self._load_plugin_module(path, folder, target)
|
||||
|
||||
if is_pre_launch:
|
||||
asyncio.run(
|
||||
self.execute_plugin(module, manifest_meta)
|
||||
)
|
||||
self._run_with_pool(module, manifest_meta)
|
||||
else:
|
||||
GLib.idle_add(
|
||||
asyncio.run,
|
||||
self.execute_plugin(module, manifest_meta)
|
||||
self._run_with_pool, module, manifest_meta
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(f"Malformed Plugin: Not loading -->: '{folder}' !")
|
||||
@@ -90,6 +88,10 @@ class PluginsController(ControllerBase, PluginsControllerMixin, PluginReloadMixi
|
||||
|
||||
os.chdir(parent_path)
|
||||
|
||||
def _run_with_pool(self, module: type, manifest_meta: ManifestMeta):
|
||||
with ThreadPoolExecutor(max_workers = 1) as executor:
|
||||
executor.submit(self.execute_plugin, module, manifest_meta)
|
||||
|
||||
def _load_plugin_module(self, path, folder, target):
|
||||
os.chdir(path)
|
||||
|
||||
@@ -125,7 +127,7 @@ class PluginsController(ControllerBase, PluginsControllerMixin, PluginReloadMixi
|
||||
manifest_metas: list = self._manifest_manager.get_post_launch_plugins()
|
||||
self._load_plugins(manifest_metas)
|
||||
|
||||
async def execute_plugin(self, module: type, manifest_meta: ManifestMeta):
|
||||
def execute_plugin(self, module: type, manifest_meta: ManifestMeta):
|
||||
plugin = module.Plugin()
|
||||
plugin.plugin_context: PluginContext = self.create_plugin_context()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user