CheeseSignal 1.2.0__py2.py3-none-any.whl → 1.2.1__py2.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.
Potentially problematic release.
This version of CheeseSignal might be problematic. Click here for more details.
- CheeseSignal/signal.py +17 -14
- {cheesesignal-1.2.0.dist-info → cheesesignal-1.2.1.dist-info}/METADATA +40 -6
- cheesesignal-1.2.1.dist-info/RECORD +6 -0
- cheesesignal-1.2.0.dist-info/RECORD +0 -6
- {cheesesignal-1.2.0.dist-info → cheesesignal-1.2.1.dist-info}/WHEEL +0 -0
- {cheesesignal-1.2.0.dist-info → cheesesignal-1.2.1.dist-info}/licenses/LICENSE +0 -0
CheeseSignal/signal.py
CHANGED
|
@@ -153,9 +153,6 @@ class Signal:
|
|
|
153
153
|
- expected_receive_num: 期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
154
154
|
|
|
155
155
|
- auto_remove: 是否自动删除响应次数超出期望次数的接收器。
|
|
156
|
-
|
|
157
|
-
- Raise
|
|
158
|
-
- ValueError: 已有重复的函数接收器。
|
|
159
156
|
'''
|
|
160
157
|
|
|
161
158
|
@overload
|
|
@@ -175,9 +172,6 @@ class Signal:
|
|
|
175
172
|
- expected_receive_num: 期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
176
173
|
|
|
177
174
|
- auto_remove: 是否自动删除响应次数超出期望次数的接收器。
|
|
178
|
-
|
|
179
|
-
- Raise
|
|
180
|
-
- ValueError: 已有重复的函数接收器。
|
|
181
175
|
'''
|
|
182
176
|
|
|
183
177
|
def connect(self, arg1: Callable | None = None, *, expected_receive_num: int = 0, auto_remove: bool = False, runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT'] = 'ORDERED'):
|
|
@@ -190,9 +184,8 @@ class Signal:
|
|
|
190
184
|
self._connect(arg1, expected_receive_num = expected_receive_num, auto_remove = auto_remove, runType = runType)
|
|
191
185
|
|
|
192
186
|
def _connect(self, fn: Callable, *, expected_receive_num: int, auto_remove: bool, runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT']):
|
|
193
|
-
for receiver in self.receivers:
|
|
194
|
-
|
|
195
|
-
raise ValueError('已有重复的函数接收器')
|
|
187
|
+
if any(receiver.fn == fn for receiver in self.receivers):
|
|
188
|
+
raise ValueError('已有重复的函数接收器')
|
|
196
189
|
|
|
197
190
|
self.receivers.append(Receiver(self, fn, expected_receive_num = expected_receive_num, auto_remove = auto_remove, runType = runType))
|
|
198
191
|
|
|
@@ -211,6 +204,9 @@ class Signal:
|
|
|
211
204
|
|
|
212
205
|
self._total_send_num += 1
|
|
213
206
|
|
|
207
|
+
if not self.receivers:
|
|
208
|
+
return []
|
|
209
|
+
|
|
214
210
|
results = []
|
|
215
211
|
for receiver in self.receivers[:]:
|
|
216
212
|
if receiver.active and receiver.is_unexpired:
|
|
@@ -243,6 +239,10 @@ class Signal:
|
|
|
243
239
|
'''
|
|
244
240
|
|
|
245
241
|
self._total_send_num += 1
|
|
242
|
+
|
|
243
|
+
if not self.receivers:
|
|
244
|
+
return [], []
|
|
245
|
+
|
|
246
246
|
receivers = [receiver for receiver in self.receivers.copy() if receiver.active and receiver.is_unexpired]
|
|
247
247
|
|
|
248
248
|
[asyncio.create_task(receiver.fn(*args, **kwargs)) for receiver in receivers if receiver.runType == 'NO_WAIT']
|
|
@@ -250,6 +250,11 @@ class Signal:
|
|
|
250
250
|
concurrent_results = await asyncio.gather(*concurrent_tasks) if concurrent_tasks else []
|
|
251
251
|
ordered_results = [await receiver.fn(*args, **kwargs) for receiver in receivers if receiver.runType == 'ORDERED']
|
|
252
252
|
|
|
253
|
+
for receiver in receivers:
|
|
254
|
+
receiver._total_receive_num += 1
|
|
255
|
+
if receiver.is_expired:
|
|
256
|
+
self.receivers.remove(receiver)
|
|
257
|
+
|
|
253
258
|
return concurrent_results, ordered_results
|
|
254
259
|
|
|
255
260
|
def disconnect(self, fn: Callable):
|
|
@@ -318,7 +323,7 @@ class Signal:
|
|
|
318
323
|
|
|
319
324
|
def index(self, fn: Callable) -> int:
|
|
320
325
|
'''
|
|
321
|
-
|
|
326
|
+
获取接收器的顺序位置;若`runType != 'ORDERED'`,则为-1。
|
|
322
327
|
|
|
323
328
|
>>> from CheeseSignal import Signal
|
|
324
329
|
>>>
|
|
@@ -334,11 +339,9 @@ class Signal:
|
|
|
334
339
|
- ValueError: 未找到该函数的接收器。
|
|
335
340
|
'''
|
|
336
341
|
|
|
337
|
-
i
|
|
338
|
-
for receiver in self.receivers:
|
|
342
|
+
for i, receiver in enumerate(self.receivers):
|
|
339
343
|
if receiver.fn == fn:
|
|
340
|
-
return i
|
|
341
|
-
i += 1
|
|
344
|
+
return i + 1 if receiver.runType == 'ORDERED' else -1
|
|
342
345
|
|
|
343
346
|
raise ValueError('未找到该函数的接收器')
|
|
344
347
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: CheeseSignal
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: 一款简约的信号系统。
|
|
5
5
|
Project-URL: Source, https://github.com/CheeseUnknown/CheeseSignal
|
|
6
6
|
Author-email: Cheese Unknown <cheese@cheese.ren>
|
|
@@ -66,7 +66,7 @@ signal = Signal()
|
|
|
66
66
|
|
|
67
67
|
【只读】 总计信号发送次数。
|
|
68
68
|
|
|
69
|
-
#### **`def connect(self, fn: Callable, *, expected_receive_num: int = 0, auto_remove: bool = False)`**
|
|
69
|
+
#### **`def connect(self, fn: Callable, *, expected_receive_num: int = 0, auto_remove: bool = False, runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT'] = 'ORDERED')`**
|
|
70
70
|
|
|
71
71
|
通过函数注册响应函数。
|
|
72
72
|
|
|
@@ -76,11 +76,19 @@ signal = Signal()
|
|
|
76
76
|
|
|
77
77
|
- `auto_remove`: 是否自动删除响应次数超出期望次数的接收器。
|
|
78
78
|
|
|
79
|
+
- `runType`: 运行的方式,仅在`async_send`时有效。
|
|
80
|
+
|
|
81
|
+
- ORDERED: 按顺序执行,返回结果。
|
|
82
|
+
|
|
83
|
+
- CONCURRENT: 并行执行,返回结果。
|
|
84
|
+
|
|
85
|
+
- NO_WAIT: 并行执行,不阻塞代码。
|
|
86
|
+
|
|
79
87
|
- **报错**
|
|
80
88
|
|
|
81
89
|
- `ValueError`: 已有重复的函数接收器。
|
|
82
90
|
|
|
83
|
-
#### **`def connect(self, *, expected_receive_num: int = 0, auto_remove: bool = False)`**
|
|
91
|
+
#### **`def connect(self, *, expected_receive_num: int = 0, auto_remove: bool = False, runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT'] = 'ORDERED')`**
|
|
84
92
|
|
|
85
93
|
通过装饰器注册响应函数。
|
|
86
94
|
|
|
@@ -90,6 +98,14 @@ signal = Signal()
|
|
|
90
98
|
|
|
91
99
|
- `auto_remove`: 是否自动删除响应次数超出期望次数的接收器。
|
|
92
100
|
|
|
101
|
+
- `runType`: 运行的方式,仅在`async_send`时有效。
|
|
102
|
+
|
|
103
|
+
- ORDERED: 按顺序执行,返回结果。
|
|
104
|
+
|
|
105
|
+
- CONCURRENT: 并行执行,返回结果。
|
|
106
|
+
|
|
107
|
+
- NO_WAIT: 并行执行,不阻塞代码。
|
|
108
|
+
|
|
93
109
|
- **报错**
|
|
94
110
|
|
|
95
111
|
- `ValueError`: 已有重复的函数接收器。
|
|
@@ -164,9 +180,9 @@ print(signal.get_receiver(receiver))
|
|
|
164
180
|
|
|
165
181
|
- `ValueError`: 未找到该函数的接收器。
|
|
166
182
|
|
|
167
|
-
#### **`def index(self, fn: Callable) ->
|
|
183
|
+
#### **`def index(self, fn: Callable) -> int`**
|
|
168
184
|
|
|
169
|
-
|
|
185
|
+
获取接收器的顺序位置;若`runType != 'ORDERED'`,则为-1。
|
|
170
186
|
|
|
171
187
|
```python
|
|
172
188
|
from CheeseSignal import Signal
|
|
@@ -192,7 +208,7 @@ print(signal.index(receiver))
|
|
|
192
208
|
from CheeseSignal import Receiver
|
|
193
209
|
```
|
|
194
210
|
|
|
195
|
-
#### **`def __init__(self, signal: Signal, fn: Callable, *, expected_receive_num: int, auto_remove: bool)`**
|
|
211
|
+
#### **`def __init__(self, signal: Signal, fn: Callable, *, expected_receive_num: int, auto_remove: bool, runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT'] = 'ORDERED')`**
|
|
196
212
|
|
|
197
213
|
- **参数**
|
|
198
214
|
|
|
@@ -200,6 +216,14 @@ from CheeseSignal import Receiver
|
|
|
200
216
|
|
|
201
217
|
- `auto_remove`: 是否自动删除响应次数超出期望次数的接收器。
|
|
202
218
|
|
|
219
|
+
- `runType`: 运行的方式,仅在`async_send`时有效。
|
|
220
|
+
|
|
221
|
+
- ORDERED: 按顺序执行,返回结果。
|
|
222
|
+
|
|
223
|
+
- CONCURRENT: 并行执行,返回结果。
|
|
224
|
+
|
|
225
|
+
- NO_WAIT: 并行执行,不阻塞代码。
|
|
226
|
+
|
|
203
227
|
#### **`self.expected_receive_num: int`**
|
|
204
228
|
|
|
205
229
|
期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
@@ -232,6 +256,16 @@ from CheeseSignal import Receiver
|
|
|
232
256
|
|
|
233
257
|
【只读】 是否未过期。
|
|
234
258
|
|
|
259
|
+
#### **`self.runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT']`**
|
|
260
|
+
|
|
261
|
+
【只读】 运行的方式,仅在`async_send`时有效。
|
|
262
|
+
|
|
263
|
+
- ORDERED: 按顺序执行,返回结果。
|
|
264
|
+
|
|
265
|
+
- CONCURRENT: 并行执行,返回结果。
|
|
266
|
+
|
|
267
|
+
- NO_WAIT: 并行执行,不阻塞代码。
|
|
268
|
+
|
|
235
269
|
#### **`def reset(self)`**
|
|
236
270
|
|
|
237
271
|
重统计置数据。
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
CheeseSignal/__init__.py,sha256=--LvG_YyRo9N3ubHlhunm4FiiMD60hM2LsdB9uiprPM,49
|
|
2
|
+
CheeseSignal/signal.py,sha256=EqI99dbN7Wyxb7hvd3h9JQWruHeRHOKcHbXp4DwSfqs,11019
|
|
3
|
+
cheesesignal-1.2.1.dist-info/METADATA,sha256=3obooywZfLiOHcegmLzSU1tqml1ZrIZfklxI9aniaf4,6334
|
|
4
|
+
cheesesignal-1.2.1.dist-info/WHEEL,sha256=fl6v0VwpzfGBVsGtkAkhILUlJxROXbA3HvRL6Fe3140,105
|
|
5
|
+
cheesesignal-1.2.1.dist-info/licenses/LICENSE,sha256=5vFb3i4UDlskszJ3jGPh8bXrM_axJfDRRuvLu1M3bIs,1070
|
|
6
|
+
cheesesignal-1.2.1.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
CheeseSignal/__init__.py,sha256=--LvG_YyRo9N3ubHlhunm4FiiMD60hM2LsdB9uiprPM,49
|
|
2
|
-
CheeseSignal/signal.py,sha256=sxPyXtRIxgt23uTxn2SQjoF1QSIeRZxqz1MGwzij7to,10842
|
|
3
|
-
cheesesignal-1.2.0.dist-info/METADATA,sha256=09TA7w_cQcne48pQILYiOrSl-5K0sjat4KVUvo7jvuI,5141
|
|
4
|
-
cheesesignal-1.2.0.dist-info/WHEEL,sha256=fl6v0VwpzfGBVsGtkAkhILUlJxROXbA3HvRL6Fe3140,105
|
|
5
|
-
cheesesignal-1.2.0.dist-info/licenses/LICENSE,sha256=5vFb3i4UDlskszJ3jGPh8bXrM_axJfDRRuvLu1M3bIs,1070
|
|
6
|
-
cheesesignal-1.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|