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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.26
3
+ Version: 3.0.28
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -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 processor(
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
- # MultiThread 多线程
497
- # MultiProcess 多进程
498
+ # 并发: concurrency (同时发生)
499
+ # 并行: parallelism (同时执行)
498
500
  #
499
- # ThreadPool 线程池
500
- # Pool 进程池
501
+ # 多线程(并发): ThreadPoolExecutor
502
+ # 多进程(并行): ProcessPoolExecutor
501
503
  #
502
- # ThreadPool 共享内存, Pool 不共享内存
503
- # ThreadPool 可以解决 Pool 在某些情况下产生的 Can't pickle local object 的错误
504
- # https://stackoverflow.com/a/58897266
504
+ # thread: True 使用多线程
505
+ # thread: False 使用多进程 (默认)
505
506
  #
506
- # 如果要启动一个新的进程或者线程, 将 workers 设置为 1 即可
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.26
3
+ Version: 3.0.28
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="3.0.26",
7
+ version="3.0.28",
8
8
  author="septvean",
9
9
  author_email="septvean@gmail.com",
10
10
  description="Easy Kit",
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