ErisPulse 2.1.13rc3__py3-none-any.whl → 2.1.14a1__py3-none-any.whl

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.
ErisPulse/Core/util.py DELETED
@@ -1,123 +0,0 @@
1
- """
2
- ErisPulse 工具函数集合
3
-
4
- 提供常用工具函数,包括拓扑排序、缓存装饰器、异步执行等实用功能。
5
-
6
- {!--< tips >!--}
7
- 1. 使用@cache装饰器缓存函数结果
8
- 2. 使用@run_in_executor在独立线程中运行同步函数
9
- 3. 使用@retry实现自动重试机制
10
- {!--< /tips >!--}
11
- """
12
-
13
- import time
14
- import asyncio
15
- import functools
16
- import traceback
17
- from concurrent.futures import ThreadPoolExecutor
18
- from collections import defaultdict, deque
19
- from typing import List, Dict, Type, Callable, Any, Optional, Set
20
-
21
- executor = ThreadPoolExecutor()
22
-
23
- class Util:
24
- """
25
- 工具函数集合
26
-
27
- 提供各种实用功能,简化开发流程
28
-
29
- {!--< tips >!--}
30
- 1. 拓扑排序用于解决依赖关系
31
- 2. 装饰器简化常见模式实现
32
- 3. 异步执行提升性能
33
- {!--< /tips >!--}
34
- """
35
- def ExecAsync(self, async_func: Callable, *args: Any, **kwargs: Any) -> Any:
36
- """
37
- 异步执行函数
38
-
39
- :param async_func: 异步函数
40
- :param args: 位置参数
41
- :param kwargs: 关键字参数
42
- :return: 函数执行结果
43
-
44
- :example:
45
- >>> result = util.ExecAsync(my_async_func, arg1, arg2)
46
- """
47
- loop = asyncio.get_event_loop()
48
- return loop.run_in_executor(executor, lambda: asyncio.run(async_func(*args, **kwargs)))
49
-
50
- def cache(self, func: Callable) -> Callable:
51
- """
52
- 缓存装饰器
53
-
54
- :param func: 被装饰函数
55
- :return: 装饰后的函数
56
-
57
- :example:
58
- >>> @util.cache
59
- >>> def expensive_operation(param):
60
- >>> return heavy_computation(param)
61
- """
62
- cache_dict = {}
63
- @functools.wraps(func)
64
- def wrapper(*args, **kwargs):
65
- key = (args, tuple(sorted(kwargs.items())))
66
- if key not in cache_dict:
67
- cache_dict[key] = func(*args, **kwargs)
68
- return cache_dict[key]
69
- return wrapper
70
-
71
- def run_in_executor(self, func: Callable) -> Callable:
72
- """
73
- 在独立线程中执行同步函数的装饰器
74
-
75
- :param func: 被装饰的同步函数
76
- :return: 可等待的协程函数
77
-
78
- :example:
79
- >>> @util.run_in_executor
80
- >>> def blocking_io():
81
- >>> # 执行阻塞IO操作
82
- >>> return result
83
- """
84
- @functools.wraps(func)
85
- async def wrapper(*args, **kwargs):
86
- loop = asyncio.get_event_loop()
87
- try:
88
- return await loop.run_in_executor(None, lambda: func(*args, **kwargs))
89
- except Exception as e:
90
- from . import logger
91
- logger.error(f"线程内发生未处理异常:\n{''.join(traceback.format_exc())}")
92
- return wrapper
93
-
94
- def retry(self, max_attempts: int = 3, delay: int = 1) -> Callable:
95
- """
96
- 自动重试装饰器
97
-
98
- :param max_attempts: 最大重试次数 (默认: 3)
99
- :param delay: 重试间隔(秒) (默认: 1)
100
- :return: 装饰器函数
101
-
102
- :example:
103
- >>> @util.retry(max_attempts=5, delay=2)
104
- >>> def unreliable_operation():
105
- >>> # 可能失败的操作
106
- """
107
- def decorator(func: Callable) -> Callable:
108
- @functools.wraps(func)
109
- def wrapper(*args, **kwargs):
110
- attempts = 0
111
- while attempts < max_attempts:
112
- try:
113
- return func(*args, **kwargs)
114
- except Exception as e:
115
- attempts += 1
116
- if attempts == max_attempts:
117
- raise
118
- time.sleep(delay)
119
- return wrapper
120
- return decorator
121
-
122
-
123
- util = Util()
@@ -1,16 +0,0 @@
1
- ErisPulse/__init__.py,sha256=T-N56UQyBmpvlqwH2wGi5ptPzaJpbgF5tKkJt0DlkaM,26099
2
- ErisPulse/__main__.py,sha256=kGpk-BeztjhrdNwWL2mZxaVy05y4XicCS6SZGtQERho,37409
3
- ErisPulse/Core/__init__.py,sha256=tBYPahQ7-w7U6M69xy8DW0_ECa9ja-Q0y_SQqVswYBo,409
4
- ErisPulse/Core/adapter.py,sha256=ZK81dibJ471FowL0MRXkS113iBcMgj_VzpTw0PzhAEo,18102
5
- ErisPulse/Core/config.py,sha256=ZmwGdtHSOE7K5uOGzLYcyl3ZF3sAmeWAntqcdfDzhpM,5027
6
- ErisPulse/Core/env.py,sha256=HGkzsdbxh8c1GSDJhnGP9B09Sz2ZeNbRxWieaFmAcug,18870
7
- ErisPulse/Core/logger.py,sha256=cJzNXF-EmdWxwgiHg5Itmkwsva2Jhe9l9X4rXKiXHgc,8296
8
- ErisPulse/Core/mods.py,sha256=2yIq8t9Ca9CBPRiZU0yr8Lc0XGmmkB7LlH-5FWqXjw4,7023
9
- ErisPulse/Core/raiserr.py,sha256=vlyaaiOIYkyqm9dAqSW9E54JBzX-9roHDp5_r6I0yUU,5591
10
- ErisPulse/Core/server.py,sha256=FkDTeLuHD5IBnWVxvYU8pHb6yCt8GzyvC1bpOiJ7G7I,9217
11
- ErisPulse/Core/util.py,sha256=7rdMmn6sBFqYd4znxBCcJjuv2eyTExdeKyZopgds868,3796
12
- erispulse-2.1.13rc3.dist-info/METADATA,sha256=ppMW2h_uDFhvpfP9u30vbaHgQA9fr_oPdDzeWaLQRf4,6262
13
- erispulse-2.1.13rc3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- erispulse-2.1.13rc3.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
15
- erispulse-2.1.13rc3.dist-info/licenses/LICENSE,sha256=4jyqikiB0G0n06CEEMMTzTXjE4IShghSlB74skMSPQs,1464
16
- erispulse-2.1.13rc3.dist-info/RECORD,,