This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflow): support workflow executor pool
- Loading branch information
Showing
3 changed files
with
72 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from diceutils.status import StatusPool | ||
from infini.core import Core | ||
from infini.loader import Loader | ||
from infini.output import Output | ||
|
||
import importlib | ||
import sys | ||
|
||
status = StatusPool.register("dicergirl") | ||
core: Core | ||
|
||
|
||
def get_core(): | ||
return core | ||
|
||
|
||
def hmr(output: Output = None): | ||
global core | ||
importlib.invalidate_caches() | ||
|
||
packages = status.get("bot", "packages") or [] | ||
|
||
for package in packages: | ||
for name in [name for name in sys.modules.keys() if name.startswith(package)]: | ||
sys.modules[name] = ( | ||
importlib.reload(sys.modules[name]) | ||
if name in sys.modules | ||
else importlib.import_module(name) | ||
) | ||
sys.modules[package] = ( | ||
importlib.reload(sys.modules[package]) | ||
if package in sys.modules | ||
else importlib.import_module(package) | ||
) | ||
|
||
with Loader() as loader: | ||
for package in packages: | ||
loader.load(package) | ||
core = loader.into_core() | ||
|
||
if output: | ||
output.status = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from concurrent.futures import ThreadPoolExecutor | ||
from typing import Callable | ||
from .utils import hmr | ||
|
||
pool = ThreadPoolExecutor(20) | ||
workflows = {"echo.hmr": hmr} | ||
|
||
|
||
def put(func: Callable): | ||
pool.submit(func) |