ezKit 3.0.26__tar.gz → 3.0.28__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ezkit-3.0.26/ezKit.egg-info → ezkit-3.0.28}/PKG-INFO +1 -1
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/utils.py +54 -9
- {ezkit-3.0.26 → ezkit-3.0.28/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.26 → ezkit-3.0.28}/setup.py +1 -1
- {ezkit-3.0.26 → ezkit-3.0.28}/LICENSE +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/MANIFEST.in +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/README.md +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/__init__.py +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/database.py +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/fastapix.py +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/http.py +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/markdown_to_html.template +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/markdownx.py +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/sendemail.py +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit/stock.py +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/pyproject.toml +0 -0
- {ezkit-3.0.26 → ezkit-3.0.28}/setup.cfg +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Utils Library"""
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
+
import subprocess
|
|
4
5
|
import time
|
|
5
6
|
import tomllib
|
|
6
7
|
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
|
@@ -477,7 +478,7 @@ def json_safe(value: Any) -> Any:
|
|
|
477
478
|
# --------------------------------------------------------------------------------------------------
|
|
478
479
|
|
|
479
480
|
|
|
480
|
-
def
|
|
481
|
+
def parallelism(
|
|
481
482
|
func: Callable,
|
|
482
483
|
data: list,
|
|
483
484
|
workers: int = 2,
|
|
@@ -491,19 +492,19 @@ def processor(
|
|
|
491
492
|
# :param workers: 并行数量
|
|
492
493
|
# :param thread: 是否使用多线程
|
|
493
494
|
# :param kwargs: 其他可选参数传递给线程池或进程池
|
|
495
|
+
#
|
|
494
496
|
# :return: 处理后的结果列表或 False(异常情况)
|
|
495
497
|
#
|
|
496
|
-
#
|
|
497
|
-
#
|
|
498
|
+
# 并发: concurrency (同时发生)
|
|
499
|
+
# 并行: parallelism (同时执行)
|
|
498
500
|
#
|
|
499
|
-
#
|
|
500
|
-
#
|
|
501
|
+
# 多线程(并发): ThreadPoolExecutor
|
|
502
|
+
# 多进程(并行): ProcessPoolExecutor
|
|
501
503
|
#
|
|
502
|
-
#
|
|
503
|
-
#
|
|
504
|
-
# https://stackoverflow.com/a/58897266
|
|
504
|
+
# thread: True 使用多线程
|
|
505
|
+
# thread: False 使用多进程 (默认)
|
|
505
506
|
#
|
|
506
|
-
#
|
|
507
|
+
# 如果要启动一个进程或线程, 将 workers 设置为 1 即可
|
|
507
508
|
|
|
508
509
|
info: str = f"{'multi-threading' if thread else 'multi-processing'} with {workers} workers"
|
|
509
510
|
|
|
@@ -534,3 +535,47 @@ def processor(
|
|
|
534
535
|
logger.error(e)
|
|
535
536
|
|
|
536
537
|
return False
|
|
538
|
+
|
|
539
|
+
finally:
|
|
540
|
+
|
|
541
|
+
logger.info(f"{info} | finished")
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def shell(
|
|
545
|
+
command: str,
|
|
546
|
+
isfile: bool = False,
|
|
547
|
+
sh_shell: str = "/bin/bash",
|
|
548
|
+
sh_option: str | None = None,
|
|
549
|
+
**kwargs: Any,
|
|
550
|
+
) -> subprocess.CompletedProcess[Any] | None:
|
|
551
|
+
"""执行 Shell 命令或脚本;启动失败时记录错误并返回 None。"""
|
|
552
|
+
|
|
553
|
+
if not isinstance(command, str) or not command:
|
|
554
|
+
logger.error("Invalid command input")
|
|
555
|
+
return None
|
|
556
|
+
|
|
557
|
+
if not isinstance(sh_shell, str) or not sh_shell:
|
|
558
|
+
logger.error(f"Invalid shell path: {sh_shell}")
|
|
559
|
+
return None
|
|
560
|
+
|
|
561
|
+
if not check_path_type(sh_shell, "file"):
|
|
562
|
+
logger.error(f"Invalid shell path: {sh_shell}")
|
|
563
|
+
return None
|
|
564
|
+
|
|
565
|
+
if isfile:
|
|
566
|
+
args = [sh_shell, command] if sh_option is None else [sh_shell, sh_option, command]
|
|
567
|
+
else:
|
|
568
|
+
args = [sh_shell, sh_option or "-c", command]
|
|
569
|
+
|
|
570
|
+
try:
|
|
571
|
+
|
|
572
|
+
return subprocess.run(args, **kwargs, check=False)
|
|
573
|
+
|
|
574
|
+
except Exception as e:
|
|
575
|
+
|
|
576
|
+
if DEBUG:
|
|
577
|
+
logger.exception(e)
|
|
578
|
+
else:
|
|
579
|
+
logger.error(e)
|
|
580
|
+
|
|
581
|
+
return None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|