ezKit 1.11.4__py3-none-any.whl → 1.11.5__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
ezKit/utils.py CHANGED
@@ -7,14 +7,12 @@ import os
7
7
  import subprocess
8
8
  import time
9
9
  import tomllib
10
+ from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
10
11
  from copy import deepcopy
11
12
  from itertools import islice
12
- from multiprocessing import Pool
13
- from multiprocessing.pool import ThreadPool
14
13
  from pathlib import Path
15
14
  from shutil import rmtree
16
- from types import FunctionType
17
- from typing import Any
15
+ from typing import Any, Callable
18
16
  from urllib.parse import ParseResult, urlparse
19
17
  from uuid import uuid4
20
18
 
@@ -742,7 +740,7 @@ def parent_dir(
742
740
  # --------------------------------------------------------------------------------------------------
743
741
 
744
742
 
745
- def retry(func: FunctionType, times: int = 3, **kwargs):
743
+ def retry(func: Callable, times: int = 3, **kwargs) -> Any:
746
744
  """重试"""
747
745
 
748
746
  # 函数传递参数: https://stackoverflow.com/a/803632
@@ -1191,12 +1189,12 @@ def delete_directory(
1191
1189
 
1192
1190
 
1193
1191
  def processor(
1194
- process_func: FunctionType,
1195
- process_data: list[Any],
1192
+ process_func: Callable,
1193
+ process_data: list,
1196
1194
  process_num: int = 2,
1197
1195
  thread: bool = False,
1198
1196
  **kwargs
1199
- ) -> list | bool:
1197
+ ) -> Any:
1200
1198
  """使用多线程或多进程对数据进行并行处理"""
1201
1199
 
1202
1200
  # :param process_func: 处理函数
@@ -1226,13 +1224,13 @@ def processor(
1226
1224
 
1227
1225
  # 确保并行数不超过数据量
1228
1226
  process_num = min(len(process_data), process_num)
1229
- _data_chunks = (
1227
+ data_chunks = (
1230
1228
  list_split(process_data, process_num, equally=True)
1231
1229
  if process_num > 1
1232
1230
  else [process_data]
1233
1231
  )
1234
1232
 
1235
- if not _data_chunks:
1233
+ if not data_chunks:
1236
1234
  logger.error("data chunks error")
1237
1235
  return False
1238
1236
 
@@ -1241,9 +1239,9 @@ def processor(
1241
1239
  )
1242
1240
 
1243
1241
  # 执行多线程或多进程任务
1244
- pool_cls = ThreadPool if thread else Pool
1245
- with pool_cls(process_num, **kwargs) as pool:
1246
- return pool.map(process_func, _data_chunks)
1242
+ pool = ThreadPoolExecutor if thread else ProcessPoolExecutor
1243
+ with pool(process_num, **kwargs) as executor:
1244
+ return executor.map(process_func, data_chunks)
1247
1245
 
1248
1246
  except Exception as e:
1249
1247
  logger.exception(e)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.11.4
3
+ Version: 1.11.5
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -10,10 +10,10 @@ ezKit/qywx.py,sha256=dGChIIf2V81MwufcPn6hwgSenPuxqK994KRH7ECT-CM,10387
10
10
  ezKit/redis.py,sha256=tdiqfizPYQQTIUumkJGUJsJVlv0zVTSTYGQN0QutYs4,1963
11
11
  ezKit/sendemail.py,sha256=47JTDFoLJKi0YtF3RAp9nFfo0ko2jlde3R_C1wr2E2w,7397
12
12
  ezKit/token.py,sha256=HKREyZj_T2S8-aFoFIrBXTaCKExQq4zE66OHXhGHqQg,1750
13
- ezKit/utils.py,sha256=cIoiqZXJkbdo0FtBEExOgA8jvyzjp1Yq0kvTFTc1kjs,42486
13
+ ezKit/utils.py,sha256=Mwqc6YO7_G-2ctPc7QzWzPvNtvVF5dURddBpuGnqKEg,42465
14
14
  ezKit/xftp.py,sha256=izUH9pLH_AzgR3c0g8xSfhLn7LQ9EDcTst3LFjTM6hU,7878
15
- ezKit-1.11.4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
16
- ezKit-1.11.4.dist-info/METADATA,sha256=amy4gY1s9zrVATfy2KKD0EI2xuPfTBXlBOV_1SM324g,191
17
- ezKit-1.11.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
18
- ezKit-1.11.4.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
19
- ezKit-1.11.4.dist-info/RECORD,,
15
+ ezKit-1.11.5.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
16
+ ezKit-1.11.5.dist-info/METADATA,sha256=HJXiI2z5EuVlZXuWgw5CTQEBoXD8Hat1EZOpJk9IFDI,191
17
+ ezKit-1.11.5.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
18
+ ezKit-1.11.5.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
19
+ ezKit-1.11.5.dist-info/RECORD,,
File without changes