ezKit 1.11.4__tar.gz → 1.11.6__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.11.4
3
+ Version: 1.11.6
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -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
@@ -887,7 +885,7 @@ def datetime_to_string(
887
885
 
888
886
 
889
887
  def datetime_to_timestamp(
890
- datetime_instance: datetime.datetime,
888
+ datetime_instance: datetime.datetime = datetime.datetime.now(),
891
889
  utc: bool = False
892
890
  ) -> int | None:
893
891
  """
@@ -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.6
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -3,7 +3,7 @@ from setuptools import find_packages, setup
3
3
 
4
4
  setup(
5
5
  name='ezKit',
6
- version='1.11.4',
6
+ version='1.11.6',
7
7
  author='septvean',
8
8
  author_email='septvean@gmail.com',
9
9
  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
File without changes
File without changes
File without changes
File without changes