CheeseSignal 1.2.0__py2.py3-none-any.whl → 2.1.0__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.
- CheeseSignal/signal.py +330 -276
- cheesesignal-2.1.0.dist-info/METADATA +82 -0
- cheesesignal-2.1.0.dist-info/RECORD +6 -0
- {cheesesignal-1.2.0.dist-info → cheesesignal-2.1.0.dist-info}/WHEEL +1 -1
- cheesesignal-1.2.0.dist-info/METADATA +0 -239
- cheesesignal-1.2.0.dist-info/RECORD +0 -6
- {cheesesignal-1.2.0.dist-info → cheesesignal-2.1.0.dist-info}/licenses/LICENSE +0 -0
CheeseSignal/signal.py
CHANGED
|
@@ -1,359 +1,413 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
from typing import
|
|
3
|
-
|
|
4
|
-
if TYPE_CHECKING:
|
|
5
|
-
class Signal:
|
|
6
|
-
...
|
|
1
|
+
import uuid, concurrent.futures, asyncio
|
|
2
|
+
from typing import Callable, Iterable, overload, Literal
|
|
3
|
+
from collections import OrderedDict
|
|
7
4
|
|
|
8
5
|
class Receiver:
|
|
9
|
-
|
|
6
|
+
__slots__ = ('_key', 'fn', 'run_type', '_receive_num_expected', 'auto_remove', '_receive_num')
|
|
7
|
+
|
|
8
|
+
def __init__(self, fn: Callable, key: str | None = None, *, run_type: Literal['SEQUENTIAL', 'PARALLEL', 'NO_BLOCK'] = 'SEQUENTIAL', receive_num_expected: int = 0, auto_remove: bool = False):
|
|
10
9
|
'''
|
|
11
10
|
- Args
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
-
|
|
11
|
+
- fn: 接收函数
|
|
12
|
+
- key: 若不设置则自动生成一个uuid格式的字符串
|
|
13
|
+
- run_type: 运行方式
|
|
14
|
+
- SEQUENTIAL: 顺序执行,等待函数执行完成后再执行下一个函数
|
|
15
|
+
- PARALLEL: 并行执行,等待所有函数执行完成后再继续
|
|
16
|
+
- NO_BLOCK: 非阻塞执行,函数在后台执行,不等待函数执行完成
|
|
17
|
+
- receive_num_expected: 期望接收总数
|
|
18
|
+
- auto_remove: 是否在达到期望接收总数后自动移除接收器
|
|
15
19
|
'''
|
|
16
20
|
|
|
17
|
-
self.
|
|
21
|
+
self._key: str = key or str(uuid.uuid4())
|
|
18
22
|
self.fn: Callable = fn
|
|
19
|
-
self.
|
|
20
|
-
self._auto_remove: bool = auto_remove
|
|
21
|
-
self._total_receive_num: int = 0
|
|
22
|
-
self._active: bool = True
|
|
23
|
-
self._runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT'] = runType
|
|
24
|
-
|
|
25
|
-
def reset(self):
|
|
26
|
-
'''
|
|
27
|
-
重统计置数据。
|
|
28
|
-
|
|
29
|
-
在有期望信号接受次数的情况下,`auto_remove is False`的接收器会重新开始计数并接收信号。
|
|
30
|
-
'''
|
|
31
|
-
|
|
32
|
-
self._total_receive_num = 0
|
|
33
|
-
|
|
34
|
-
@property
|
|
35
|
-
def expected_receive_num(self) -> int:
|
|
23
|
+
self.run_type: Literal['SEQUENTIAL', 'PARALLEL', 'NO_BLOCK'] = run_type
|
|
36
24
|
'''
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
运行方式
|
|
26
|
+
- SEQUENTIAL: 顺序执行,等待函数执行完成后再执行下一个函数
|
|
27
|
+
- PARALLEL: 并行执行,等待所有函数执行完成后再继续
|
|
28
|
+
- NO_BLOCK: 非阻塞执行,函数在后台执行,不等待函数执行完成
|
|
40
29
|
'''
|
|
30
|
+
self._receive_num_expected: int = receive_num_expected
|
|
31
|
+
''' 期望接收总数 '''
|
|
32
|
+
self.auto_remove: bool = auto_remove
|
|
33
|
+
''' 是否在达到期望接收总数后自动移除接收器 '''
|
|
41
34
|
|
|
42
|
-
|
|
35
|
+
self._receive_num: int = 0
|
|
36
|
+
''' 接收总数 '''
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
self._expected_receive_num = value
|
|
38
|
+
def reset(self):
|
|
39
|
+
''' 重置统计数据 '''
|
|
47
40
|
|
|
48
|
-
|
|
49
|
-
self._signal.receivers.remove(self)
|
|
41
|
+
self._receive_num = 0
|
|
50
42
|
|
|
51
43
|
@property
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
是否自动删除响应次数超出期望次数的接收器。
|
|
55
|
-
|
|
56
|
-
设置为`True`时若该receiver过期,则会立刻删除。
|
|
57
|
-
'''
|
|
58
|
-
|
|
59
|
-
return self._auto_remove
|
|
60
|
-
|
|
61
|
-
@auto_remove.setter
|
|
62
|
-
def auto_remove(self, value: bool):
|
|
63
|
-
self._auto_remove = value
|
|
64
|
-
|
|
65
|
-
if self._auto_remove and self.is_expired:
|
|
66
|
-
self._signal.receivers.remove(self)
|
|
44
|
+
def key(self) -> str:
|
|
45
|
+
return self._key
|
|
67
46
|
|
|
68
47
|
@property
|
|
69
|
-
def
|
|
70
|
-
'''
|
|
71
|
-
是否激活;未激活将忽略信号。
|
|
72
|
-
'''
|
|
73
|
-
|
|
74
|
-
return self._active
|
|
48
|
+
def receive_num(self) -> int:
|
|
49
|
+
''' 接收总数 '''
|
|
75
50
|
|
|
76
|
-
|
|
77
|
-
def active(self, value: bool):
|
|
78
|
-
self._active = value
|
|
51
|
+
return self._receive_num
|
|
79
52
|
|
|
80
53
|
@property
|
|
81
|
-
def
|
|
82
|
-
'''
|
|
83
|
-
【只读】 总计信号接受次数。
|
|
84
|
-
'''
|
|
54
|
+
def receive_num_expected(self) -> int:
|
|
55
|
+
''' 期望接收总数 '''
|
|
85
56
|
|
|
86
|
-
return self.
|
|
57
|
+
return self._receive_num_expected
|
|
87
58
|
|
|
88
59
|
@property
|
|
89
|
-
def
|
|
90
|
-
'''
|
|
91
|
-
【只读】 剩余的期望信号接受次数;返回为-1代表无期望信号接受次数。
|
|
92
|
-
'''
|
|
60
|
+
def receive_num_remaining(self) -> int | None:
|
|
61
|
+
''' 剩余接收总数 '''
|
|
93
62
|
|
|
94
|
-
|
|
95
|
-
return -1
|
|
96
|
-
return self.expected_receive_num - self.total_receive_num
|
|
63
|
+
return self._receive_num_expected - self._receive_num if self._receive_num_expected > 0 else None
|
|
97
64
|
|
|
98
65
|
@property
|
|
99
|
-
def
|
|
100
|
-
'''
|
|
101
|
-
【只读】 是否过期。
|
|
102
|
-
'''
|
|
103
|
-
|
|
104
|
-
return not self.is_unexpired
|
|
66
|
+
def is_active(self) -> bool:
|
|
67
|
+
''' 是否处于激活状态 '''
|
|
105
68
|
|
|
106
|
-
|
|
107
|
-
def is_unexpired(self) -> bool:
|
|
108
|
-
'''
|
|
109
|
-
【只读】 是否未过期。
|
|
110
|
-
'''
|
|
69
|
+
return self._receive_num_expected == 0 or self.receive_num_remaining > 0
|
|
111
70
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return True if self.remaining_receive_num else False
|
|
71
|
+
class Signal:
|
|
72
|
+
__slots__ = ('receivers', '_send_num')
|
|
115
73
|
|
|
116
|
-
|
|
117
|
-
def runType(self) -> Literal['ORDERED', 'CONCURRENT', 'NO_WAIT']:
|
|
74
|
+
def __init__(self):
|
|
118
75
|
'''
|
|
119
|
-
|
|
76
|
+
- Examples
|
|
77
|
+
```python
|
|
78
|
+
""" 基础用法 """
|
|
79
|
+
from CheeseSignal import Signal
|
|
120
80
|
|
|
121
|
-
|
|
81
|
+
signal = Signal()
|
|
122
82
|
|
|
123
|
-
|
|
83
|
+
def handle_1():
|
|
84
|
+
print('Handler 1 executed')
|
|
85
|
+
signal.connect(handle_1)
|
|
124
86
|
|
|
125
|
-
|
|
126
|
-
|
|
87
|
+
@signal.connect()
|
|
88
|
+
def handle_2():
|
|
89
|
+
print('Handler 2 executed')
|
|
127
90
|
|
|
128
|
-
|
|
91
|
+
if __name__ == '__main__':
|
|
92
|
+
signal.send()
|
|
129
93
|
|
|
130
|
-
@runType.setter
|
|
131
|
-
def runType(self, value: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT']):
|
|
132
|
-
self._runType = value
|
|
133
94
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
self._receivers: List[Receiver] = []
|
|
137
|
-
self._total_send_num: int = 0
|
|
95
|
+
""" 异步用法 """
|
|
96
|
+
import asyncio
|
|
138
97
|
|
|
139
|
-
|
|
140
|
-
def connect(self, fn: Callable, *, expected_receive_num: int = 0, auto_remove: bool = False, runType: Literal['ORDERED', 'CONCURRENT', 'NO_WAIT'] = 'ORDERED'):
|
|
141
|
-
'''
|
|
142
|
-
通过函数注册响应函数。
|
|
98
|
+
from CheeseSignal import Signal
|
|
143
99
|
|
|
144
|
-
|
|
145
|
-
>>>
|
|
146
|
-
>>> def receiver(*args, **kwargs):
|
|
147
|
-
... ...
|
|
148
|
-
>>>
|
|
149
|
-
>>> signal = Signal()
|
|
150
|
-
>>> signal.connect(receiver)
|
|
100
|
+
signal = Signal()
|
|
151
101
|
|
|
152
|
-
|
|
153
|
-
|
|
102
|
+
async def handle_1():
|
|
103
|
+
print('Handler 1 executed')
|
|
104
|
+
signal.connect(handle_1)
|
|
154
105
|
|
|
155
|
-
|
|
106
|
+
@signal.connect()
|
|
107
|
+
async def handle_2():
|
|
108
|
+
print('Handler 2 executed')
|
|
156
109
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
'''
|
|
110
|
+
if __name__ == '__main__':
|
|
111
|
+
asyncio.run(signal.async_send())
|
|
160
112
|
|
|
161
|
-
@overload
|
|
162
|
-
def connect(self, *, expected_receive_num: int = 0, auto_remove: bool = False):
|
|
163
|
-
'''
|
|
164
|
-
通过装饰器注册响应函数。
|
|
165
113
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
>>> signal = Signal()
|
|
169
|
-
>>>
|
|
170
|
-
>>> @signal.connect()
|
|
171
|
-
>>> def receiver(*args, **kwargs):
|
|
172
|
-
... ...
|
|
114
|
+
""" 期望接收数与自动删除 """
|
|
115
|
+
from CheeseSignal import Signal
|
|
173
116
|
|
|
174
|
-
|
|
175
|
-
- expected_receive_num: 期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
117
|
+
signal = Signal()
|
|
176
118
|
|
|
177
|
-
|
|
119
|
+
@signal.connect(receive_num_expected = 3)
|
|
120
|
+
def handle_1():
|
|
121
|
+
print('Handler 1 executed')
|
|
178
122
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
123
|
+
@signal.connect(receive_num_expected = 3, auto_remove = True)
|
|
124
|
+
def handle_2():
|
|
125
|
+
print('Handler 2 executed')
|
|
182
126
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
127
|
+
if __name__ == '__main__':
|
|
128
|
+
for i in range(5):
|
|
129
|
+
signal.send()
|
|
130
|
+
print(list(signal.receivers.keys()))
|
|
131
|
+
```
|
|
132
|
+
'''
|
|
189
133
|
|
|
190
|
-
self.
|
|
134
|
+
self.receivers: OrderedDict[str, Receiver] = OrderedDict()
|
|
135
|
+
''' 连接的接收器'''
|
|
136
|
+
self._send_num: int = 0
|
|
137
|
+
''' 发送总数 '''
|
|
191
138
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
raise ValueError('已有重复的函数接收器')
|
|
139
|
+
@overload
|
|
140
|
+
def get_receiver(self, key: str) -> Receiver | None:
|
|
141
|
+
''' 获取接收器 '''
|
|
196
142
|
|
|
197
|
-
|
|
143
|
+
@overload
|
|
144
|
+
def get_receiver(self, fn: Callable) -> Receiver | None:
|
|
145
|
+
''' 获取接收器 '''
|
|
146
|
+
|
|
147
|
+
def get_receiver(self, arg: str | Callable) -> Receiver | None:
|
|
148
|
+
if type(arg) == str:
|
|
149
|
+
return self.receivers.get(arg, None)
|
|
150
|
+
elif callable(arg):
|
|
151
|
+
for receiver in self.receivers.values():
|
|
152
|
+
if receiver.fn == arg:
|
|
153
|
+
return receiver
|
|
154
|
+
|
|
155
|
+
def _connect(self, fn: Callable, key: str | None = None, *, index: int = -1, insert: tuple[str | Callable | Receiver, Literal['BEFORE', 'AFTER']] | None = None, run_type: Literal['SEQUENTIAL', 'PARALLEL', 'NO_BLOCK'] = 'SEQUENTIAL', receive_num_expected: int = 0, auto_remove: bool = False):
|
|
156
|
+
if key in self.receivers:
|
|
157
|
+
raise ValueError(f'Receiver "{key}" already exists')
|
|
158
|
+
|
|
159
|
+
receiver = Receiver(fn, key, run_type = run_type, receive_num_expected = receive_num_expected, auto_remove = auto_remove)
|
|
160
|
+
items = list(self.receivers.items())
|
|
161
|
+
if index > -1:
|
|
162
|
+
items.insert(index, (receiver.key, receiver))
|
|
163
|
+
self.receivers.clear()
|
|
164
|
+
self.receivers.update(items)
|
|
165
|
+
elif insert:
|
|
166
|
+
if isinstance(insert[0], Receiver):
|
|
167
|
+
key = insert[0].key
|
|
168
|
+
if key not in self.receivers:
|
|
169
|
+
raise ValueError(f'Receiver "{key}" does not exist')
|
|
170
|
+
elif callable(insert[0]):
|
|
171
|
+
_receiver = self.get_receiver(insert[0])
|
|
172
|
+
if not _receiver:
|
|
173
|
+
raise ValueError(f'Receiver "{insert[0]}" does not exist')
|
|
174
|
+
key = _receiver.key
|
|
175
|
+
elif isinstance(insert[0], str):
|
|
176
|
+
key = insert[0]
|
|
177
|
+
if key not in self.receivers:
|
|
178
|
+
raise ValueError(f'Receiver "{key}" does not exist')
|
|
179
|
+
|
|
180
|
+
for i, (_key, _) in enumerate(items):
|
|
181
|
+
if _key == key:
|
|
182
|
+
if insert[1] == 'BEFORE':
|
|
183
|
+
items.insert(i, (receiver.key, receiver))
|
|
184
|
+
elif insert[1] == 'AFTER':
|
|
185
|
+
items.insert(i + 1, (receiver.key, receiver))
|
|
186
|
+
break
|
|
187
|
+
else:
|
|
188
|
+
self.receivers[receiver.key] = receiver
|
|
198
189
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
发送信号。
|
|
202
|
-
|
|
203
|
-
>>> from CheeseSignal import Signal
|
|
204
|
-
>>>
|
|
205
|
-
>>> signal = Signal()
|
|
206
|
-
>>> signal.send('data1', 'data2', **{
|
|
207
|
-
... 'key1': 'value1',
|
|
208
|
-
... 'key2': 'value2'
|
|
209
|
-
>>> })
|
|
190
|
+
@overload
|
|
191
|
+
def connect(self, fn: Callable, key: str | None = None, *, index: int = -1, insert: tuple[str | Callable | Receiver, Literal['BEFORE', 'AFTER']] | None = None, run_type: Literal['SEQUENTIAL', 'PARALLEL', 'NO_BLOCK'] = 'SEQUENTIAL', receive_num_expected: int = 0, auto_remove: bool = False):
|
|
210
192
|
'''
|
|
193
|
+
连接接收器
|
|
211
194
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
... 'key1': 'value1',
|
|
236
|
-
... 'key2': 'value2'
|
|
237
|
-
... })
|
|
238
|
-
>>>
|
|
239
|
-
>>> asyncio.run(run_asyncio())
|
|
240
|
-
|
|
241
|
-
- Returns
|
|
242
|
-
返回长度为2的元祖,分别为ORDERED类型和CONCURRENT类型的结果。
|
|
195
|
+
- Args
|
|
196
|
+
- key: 接收器键值,若不设置则自动生成一个uuid格式的字符串
|
|
197
|
+
- run_type: 运行类型
|
|
198
|
+
- SEQUENTIAL: 顺序执行,等待函数执行完成后再执行下一个函数
|
|
199
|
+
- PARALLEL: 并行执行,等待所有函数执行完成后再继续
|
|
200
|
+
- NO_BLOCK: 非阻塞执行,函数在后台执行,不等待函数执行完成
|
|
201
|
+
- receive_num_expected: 期望接收总数
|
|
202
|
+
- auto_remove: 是否在达到期望接收总数后自动移除接收器
|
|
203
|
+
- index: 插入位置索引(仅对run_type为SEQUENTIAL的接收器有效)
|
|
204
|
+
- insert: 插入位置;若设置index,则忽略此参数(仅对run_type为SEQUENTIAL的接收器有效)
|
|
205
|
+
- BEFORE: 插入到指定接收器之前
|
|
206
|
+
- AFTER: 插入到指定接收器之后
|
|
207
|
+
|
|
208
|
+
- Examples
|
|
209
|
+
```python
|
|
210
|
+
from CheeseSignal import Signal
|
|
211
|
+
|
|
212
|
+
signal = Signal()
|
|
213
|
+
|
|
214
|
+
def handler():
|
|
215
|
+
print('Handler executed')
|
|
216
|
+
signal.connect(handler)
|
|
217
|
+
```
|
|
243
218
|
'''
|
|
244
219
|
|
|
245
|
-
|
|
246
|
-
|
|
220
|
+
@overload
|
|
221
|
+
def connect(self, key: str | None = None, *, index: int = -1, insert: tuple[str | Callable | Receiver, Literal['BEFORE', 'AFTER']] | None = None, run_type: Literal['SEQUENTIAL', 'PARALLEL', 'NO_BLOCK'] = 'SEQUENTIAL', receive_num_expected: int = 0, auto_remove: bool = False):
|
|
222
|
+
'''
|
|
223
|
+
连接接收器
|
|
247
224
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
225
|
+
- Args
|
|
226
|
+
- key: 接收器键值,若不设置则自动生成一个uuid格式的字符串
|
|
227
|
+
- run_type: 运行类型
|
|
228
|
+
- SEQUENTIAL: 顺序执行,等待函数执行完成后再执行下一个函数
|
|
229
|
+
- PARALLEL: 并行执行,等待所有函数执行完成后再继续
|
|
230
|
+
- NO_BLOCK: 非阻塞执行,函数在后台执行,不等待函数执行完成
|
|
231
|
+
- receive_num_expected: 期望接收总数
|
|
232
|
+
- auto_remove: 是否在达到期望接收总数后自动移除接收器
|
|
233
|
+
- index: 插入位置索引(仅对run_type为SEQUENTIAL的接收器有效)
|
|
234
|
+
- insert: 插入位置;若设置index,则忽略此参数(仅对run_type为SEQUENTIAL的接收器有效)
|
|
235
|
+
- BEFORE: 插入到指定接收器之前
|
|
236
|
+
- AFTER: 插入到指定接收器之后
|
|
237
|
+
|
|
238
|
+
- Examples
|
|
239
|
+
```python
|
|
240
|
+
from CheeseSignal import Signal
|
|
241
|
+
|
|
242
|
+
signal = Signal()
|
|
243
|
+
|
|
244
|
+
@signal.connect()
|
|
245
|
+
def handler():
|
|
246
|
+
print('Handler executed')
|
|
247
|
+
```
|
|
248
|
+
'''
|
|
249
|
+
|
|
250
|
+
def connect(self, arg1: Callable | str | None = None, *args, index: int = -1, insert: tuple[str | Callable | Receiver, Literal['BEFORE', 'AFTER']] | None = None, run_type: Literal['SEQUENTIAL', 'PARALLEL', 'NO_BLOCK'] = 'SEQUENTIAL', receive_num_expected: int = 0, auto_remove: bool = False):
|
|
251
|
+
if callable(arg1):
|
|
252
|
+
self._connect(arg1, *args, index = index, insert = insert, run_type = run_type, receive_num_expected = receive_num_expected, auto_remove = auto_remove)
|
|
253
|
+
else:
|
|
254
|
+
def decorator(fn: Callable):
|
|
255
|
+
self._connect(fn, arg1, index = index, insert = insert, run_type = run_type, receive_num_expected = receive_num_expected, auto_remove = auto_remove)
|
|
256
|
+
return fn
|
|
257
|
+
return decorator
|
|
252
258
|
|
|
253
|
-
|
|
259
|
+
@overload
|
|
260
|
+
def disconnect(self, key: str):
|
|
261
|
+
''' 断开接收器 '''
|
|
254
262
|
|
|
263
|
+
@overload
|
|
255
264
|
def disconnect(self, fn: Callable):
|
|
256
|
-
'''
|
|
257
|
-
断开接收器。
|
|
258
|
-
|
|
259
|
-
>>> from CheeseSignal import Signal
|
|
260
|
-
>>>
|
|
261
|
-
>>> def receiver(*args, **kwargs):
|
|
262
|
-
... ...
|
|
263
|
-
>>>
|
|
264
|
-
>>> signal = Signal()
|
|
265
|
-
>>> signal.connect(receiver)
|
|
266
|
-
>>> signal.disconnect(receiver)
|
|
267
|
-
|
|
268
|
-
- Raise
|
|
269
|
-
- ValueError: 未找到该函数的接收器。
|
|
270
|
-
'''
|
|
265
|
+
''' 断开接收器 '''
|
|
271
266
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
267
|
+
@overload
|
|
268
|
+
def disconnect(self, receiver: Receiver):
|
|
269
|
+
''' 断开接收器 '''
|
|
270
|
+
|
|
271
|
+
def disconnect(self, arg):
|
|
272
|
+
if isinstance(arg, str):
|
|
273
|
+
key = arg
|
|
274
|
+
if key in self.receivers:
|
|
275
|
+
del self.receivers[key]
|
|
276
|
+
elif callable(arg):
|
|
277
|
+
for key in [key for key, receiver in self.receivers.items() if receiver.fn == arg]:
|
|
278
|
+
del self.receivers[key]
|
|
279
|
+
elif isinstance(arg, Receiver):
|
|
280
|
+
if arg.key in self.receivers:
|
|
281
|
+
del self.receivers[arg.key]
|
|
282
|
+
|
|
283
|
+
def disconnect_all(self):
|
|
284
|
+
''' 断开所有接收器 '''
|
|
276
285
|
|
|
277
|
-
|
|
286
|
+
self.receivers.clear()
|
|
278
287
|
|
|
279
288
|
def reset(self):
|
|
280
|
-
'''
|
|
281
|
-
重置统计数据;所有的接收器的统计数据也会同步清空。
|
|
282
|
-
'''
|
|
289
|
+
''' 重置统计数据 '''
|
|
283
290
|
|
|
284
|
-
self.
|
|
285
|
-
for receiver in self.receivers:
|
|
291
|
+
self._send_num = 0
|
|
292
|
+
for receiver in self.receivers.values():
|
|
286
293
|
receiver.reset()
|
|
287
294
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
断开所有接收器。
|
|
295
|
+
@overload
|
|
296
|
+
def send(self, key: str, *, args: tuple[any, ...], kwargs: dict[str, any]):
|
|
291
297
|
'''
|
|
298
|
+
发送信号
|
|
292
299
|
|
|
293
|
-
|
|
300
|
+
- Args
|
|
301
|
+
- args: *args参数
|
|
302
|
+
- kwargs: **kwargs参数
|
|
303
|
+
'''
|
|
294
304
|
|
|
295
|
-
|
|
305
|
+
@overload
|
|
306
|
+
def send(self, keys: Iterable[str], *, args: tuple[any, ...], kwargs: dict[str, any]):
|
|
296
307
|
'''
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
... ...
|
|
303
|
-
>>>
|
|
304
|
-
>>> signal = Signal()
|
|
305
|
-
>>> signal.connect(receiver)
|
|
306
|
-
>>>
|
|
307
|
-
>>> print(signal.get_receiver(receiver))
|
|
308
|
-
|
|
309
|
-
- Raise
|
|
310
|
-
- ValueError: 未找到该函数的接收器。
|
|
308
|
+
发送信号
|
|
309
|
+
|
|
310
|
+
- Args
|
|
311
|
+
- args: *args参数
|
|
312
|
+
- kwargs: **kwargs参数
|
|
311
313
|
'''
|
|
312
314
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
315
|
+
@overload
|
|
316
|
+
def send(self, *, args: tuple[any, ...], kwargs: dict[str, any]):
|
|
317
|
+
'''
|
|
318
|
+
发送信号
|
|
316
319
|
|
|
317
|
-
|
|
320
|
+
- Args
|
|
321
|
+
- args: *args参数
|
|
322
|
+
- kwargs: **kwargs参数
|
|
323
|
+
'''
|
|
324
|
+
|
|
325
|
+
def send(self, arg: str | list[str] | None = None, **kwargs):
|
|
326
|
+
if type(arg) == str:
|
|
327
|
+
self.send([arg], **kwargs)
|
|
328
|
+
elif isinstance(arg, Iterable):
|
|
329
|
+
sequential_receivers = [self.receivers[key] for key in arg if key in self.receivers and self.receivers[key].run_type == 'SEQUENTIAL' and self.receivers[key].is_active]
|
|
330
|
+
if sequential_receivers:
|
|
331
|
+
for receiver in sequential_receivers:
|
|
332
|
+
self._send_handle(receiver, **kwargs)
|
|
333
|
+
|
|
334
|
+
parallel_receivers = [self.receivers[key] for key in arg if key in self.receivers and self.receivers[key].run_type == 'PARALLEL' and self.receivers[key].is_active]
|
|
335
|
+
if parallel_receivers:
|
|
336
|
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
337
|
+
concurrent.futures.as_completed([executor.submit(self._send_handle, receiver, **kwargs) for receiver in parallel_receivers])
|
|
338
|
+
|
|
339
|
+
noBlock_receivers = [self.receivers[key] for key in arg if key in self.receivers and self.receivers[key].run_type == 'NO_BLOCK' and self.receivers[key].is_active]
|
|
340
|
+
if noBlock_receivers:
|
|
341
|
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
342
|
+
for receiver in noBlock_receivers:
|
|
343
|
+
executor.submit(self._send_handle, receiver, **kwargs)
|
|
344
|
+
else:
|
|
345
|
+
self.send(self.receivers.keys(), **kwargs)
|
|
346
|
+
|
|
347
|
+
def _send_handle(self, receiver: Receiver, **kwargs):
|
|
348
|
+
receiver.fn(*kwargs.get('args', ()), **kwargs.get('kwargs', {}))
|
|
349
|
+
receiver._receive_num += 1
|
|
350
|
+
if receiver.auto_remove and not receiver.is_active:
|
|
351
|
+
self.disconnect(receiver.key)
|
|
318
352
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
获取接收器的顺序位置。
|
|
322
|
-
|
|
323
|
-
>>> from CheeseSignal import Signal
|
|
324
|
-
>>>
|
|
325
|
-
>>> def receiver(*args, **kwargs):
|
|
326
|
-
... ...
|
|
327
|
-
>>>
|
|
328
|
-
>>> signal = Signal()
|
|
329
|
-
>>> signal.connect(receiver)
|
|
330
|
-
>>>
|
|
331
|
-
>>> print(signal.index(receiver))
|
|
332
|
-
|
|
333
|
-
- Raise
|
|
334
|
-
- ValueError: 未找到该函数的接收器。
|
|
353
|
+
@overload
|
|
354
|
+
def async_send(self, key: str, *, args: tuple[any, ...], kwargs: dict[str, any]):
|
|
335
355
|
'''
|
|
356
|
+
发送信号
|
|
336
357
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
i += 1
|
|
358
|
+
- Args
|
|
359
|
+
- args: *args参数
|
|
360
|
+
- kwargs: **kwargs参数
|
|
361
|
+
'''
|
|
342
362
|
|
|
343
|
-
|
|
363
|
+
@overload
|
|
364
|
+
def async_send(self, keys: Iterable[str], *, args: tuple[any, ...], kwargs: dict[str, any]):
|
|
365
|
+
'''
|
|
366
|
+
发送信号
|
|
344
367
|
|
|
345
|
-
|
|
346
|
-
|
|
368
|
+
- Args
|
|
369
|
+
- args: *args参数
|
|
370
|
+
- kwargs: **kwargs参数
|
|
347
371
|
'''
|
|
348
|
-
|
|
372
|
+
|
|
373
|
+
@overload
|
|
374
|
+
def async_send(self, *, args: tuple[any, ...], kwargs: dict[str, any]):
|
|
349
375
|
'''
|
|
376
|
+
发送信号
|
|
350
377
|
|
|
351
|
-
|
|
378
|
+
- Args
|
|
379
|
+
- args: *args参数
|
|
380
|
+
- kwargs: **kwargs参数
|
|
381
|
+
'''
|
|
382
|
+
|
|
383
|
+
async def async_send(self, arg: str | list[str] | None = None, **kwargs):
|
|
384
|
+
if type(arg) == str:
|
|
385
|
+
await self.async_send([arg], **kwargs)
|
|
386
|
+
elif isinstance(arg, Iterable):
|
|
387
|
+
sequential_receivers = [self.receivers[key] for key in arg if key in self.receivers and self.receivers[key].run_type == 'SEQUENTIAL' and self.receivers[key].is_active]
|
|
388
|
+
if sequential_receivers:
|
|
389
|
+
for receiver in sequential_receivers:
|
|
390
|
+
await self._async_send_handle(receiver, **kwargs)
|
|
391
|
+
|
|
392
|
+
parallel_receivers = [self.receivers[key] for key in arg if key in self.receivers and self.receivers[key].run_type == 'PARALLEL' and self.receivers[key].is_active]
|
|
393
|
+
if parallel_receivers:
|
|
394
|
+
await asyncio.gather(*[asyncio.create_task(self._async_send_handle(receiver, **kwargs)) for receiver in parallel_receivers])
|
|
395
|
+
|
|
396
|
+
noBlock_receivers = [self.receivers[key] for key in arg if key in self.receivers and self.receivers[key].run_type == 'NO_BLOCK' and self.receivers[key].is_active]
|
|
397
|
+
if noBlock_receivers:
|
|
398
|
+
for receiver in noBlock_receivers:
|
|
399
|
+
asyncio.create_task(self._async_send_handle(receiver, **kwargs))
|
|
400
|
+
else:
|
|
401
|
+
await self.async_send(self.receivers.keys(), **kwargs)
|
|
402
|
+
|
|
403
|
+
async def _async_send_handle(self, receiver: Receiver, **kwargs):
|
|
404
|
+
await receiver.fn(*kwargs.get('args', ()), **kwargs.get('kwargs', {}))
|
|
405
|
+
receiver._receive_num += 1
|
|
406
|
+
if receiver.auto_remove and receiver.receive_num_remaining == 0:
|
|
407
|
+
self.disconnect(receiver.key)
|
|
352
408
|
|
|
353
409
|
@property
|
|
354
|
-
def
|
|
355
|
-
'''
|
|
356
|
-
【只读】 总计信号发送次数。
|
|
357
|
-
'''
|
|
410
|
+
def send_num(self) -> int:
|
|
411
|
+
''' 发送总数 '''
|
|
358
412
|
|
|
359
|
-
return self.
|
|
413
|
+
return self._send_num
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: CheeseSignal
|
|
3
|
+
Version: 2.1.0
|
|
4
|
+
Summary: 一款简约的信号系统。
|
|
5
|
+
Project-URL: Source, https://github.com/CheeseUnknown/CheeseSignal
|
|
6
|
+
Author-email: Cheese Unknown <cheese@cheese.ren>
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: Signal
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# **CheeseSignal**
|
|
12
|
+
|
|
13
|
+
一款简单的信号系统。
|
|
14
|
+
|
|
15
|
+
## **示例**
|
|
16
|
+
|
|
17
|
+
### **基础用法**
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from CheeseSignal import Signal
|
|
21
|
+
|
|
22
|
+
signal = Signal()
|
|
23
|
+
|
|
24
|
+
def handle_1():
|
|
25
|
+
print('Handler 1 executed')
|
|
26
|
+
signal.connect(handle_1)
|
|
27
|
+
|
|
28
|
+
@signal.connect()
|
|
29
|
+
def handle_2():
|
|
30
|
+
print('Handler 2 executed')
|
|
31
|
+
|
|
32
|
+
if __name__ == '__main__':
|
|
33
|
+
signal.send()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### **异步用法**
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import asyncio
|
|
40
|
+
|
|
41
|
+
from CheeseSignal import Signal
|
|
42
|
+
|
|
43
|
+
signal = Signal()
|
|
44
|
+
|
|
45
|
+
async def handle_1():
|
|
46
|
+
print('Handler 1 executed')
|
|
47
|
+
signal.connect(handle_1)
|
|
48
|
+
|
|
49
|
+
@signal.connect()
|
|
50
|
+
async def handle_2():
|
|
51
|
+
print('Handler 2 executed')
|
|
52
|
+
|
|
53
|
+
if __name__ == '__main__':
|
|
54
|
+
asyncio.run(signal.async_send())
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### **期望接收数与自动删除**
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from CheeseSignal import Signal
|
|
61
|
+
|
|
62
|
+
signal = Signal()
|
|
63
|
+
|
|
64
|
+
@signal.connect(receive_num_expected = 3)
|
|
65
|
+
def handle_1():
|
|
66
|
+
print('Handler 1 executed')
|
|
67
|
+
|
|
68
|
+
@signal.connect(receive_num_expected = 3, auto_remove = True)
|
|
69
|
+
def handle_2():
|
|
70
|
+
print('Handler 2 executed')
|
|
71
|
+
|
|
72
|
+
if __name__ == '__main__':
|
|
73
|
+
for i in range(5):
|
|
74
|
+
signal.send()
|
|
75
|
+
print(list(signal.receivers.keys()))
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## **更多...**
|
|
79
|
+
|
|
80
|
+
### 1. [**Signal**](https://github.com/CheeseUnknown/CheeseSignal/blob/master/documents/Signal.md)
|
|
81
|
+
|
|
82
|
+
### 2. [**Receiver**](https://github.com/CheeseUnknown/CheeseSignal/blob/master/documents/Receiver.md)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
CheeseSignal/__init__.py,sha256=--LvG_YyRo9N3ubHlhunm4FiiMD60hM2LsdB9uiprPM,49
|
|
2
|
+
CheeseSignal/signal.py,sha256=qCe0yhSbQvsDgVebxfnTm6VoK6LGH73AajPHBnHt7AQ,15491
|
|
3
|
+
cheesesignal-2.1.0.dist-info/METADATA,sha256=ucRd0hXquuOuyZK5bTJRsxz_2YkLXGk12-i1x5VIdLA,1603
|
|
4
|
+
cheesesignal-2.1.0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
|
|
5
|
+
cheesesignal-2.1.0.dist-info/licenses/LICENSE,sha256=5vFb3i4UDlskszJ3jGPh8bXrM_axJfDRRuvLu1M3bIs,1070
|
|
6
|
+
cheesesignal-2.1.0.dist-info/RECORD,,
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: CheeseSignal
|
|
3
|
-
Version: 1.2.0
|
|
4
|
-
Summary: 一款简约的信号系统。
|
|
5
|
-
Project-URL: Source, https://github.com/CheeseUnknown/CheeseSignal
|
|
6
|
-
Author-email: Cheese Unknown <cheese@cheese.ren>
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Keywords: Signal
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
|
|
11
|
-
# **CheeseSignal**
|
|
12
|
-
|
|
13
|
-
一款简单的信号系统。
|
|
14
|
-
|
|
15
|
-
## **安装**
|
|
16
|
-
|
|
17
|
-
系统要求:Linux。
|
|
18
|
-
|
|
19
|
-
Python要求:目前仅保证支持3.11及以上版本的Python,新版本会优先支持Python的最新稳定版本。
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
pip install CheeseSignal
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## **使用**
|
|
26
|
-
|
|
27
|
-
使用方式较为简单,通过函数或装饰件连接至某个信号,随后等待信号发送。
|
|
28
|
-
|
|
29
|
-
```python
|
|
30
|
-
import time
|
|
31
|
-
|
|
32
|
-
from CheeseSignal import signal
|
|
33
|
-
|
|
34
|
-
signal = Signal()
|
|
35
|
-
|
|
36
|
-
def receiver1(*args, **kwargs):
|
|
37
|
-
print(arg, kwargs)
|
|
38
|
-
signal.connect(receiver1)
|
|
39
|
-
|
|
40
|
-
@signal.connect()
|
|
41
|
-
def receiver2(*args, **kwargs):
|
|
42
|
-
return args, kwargs
|
|
43
|
-
|
|
44
|
-
while True:
|
|
45
|
-
print(signal.send('Hello', 'World', {
|
|
46
|
-
'Cheese': 'Signal'
|
|
47
|
-
}))
|
|
48
|
-
time.sleep(1)
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## **接口文档**
|
|
52
|
-
|
|
53
|
-
### **`class Signal`**
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
from CheeseSignal import Signal
|
|
57
|
-
|
|
58
|
-
signal = Signal()
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
#### **`self.receivers: List[Receiver]`**
|
|
62
|
-
|
|
63
|
-
【只读】 接收器的列表,按注册顺序排序。
|
|
64
|
-
|
|
65
|
-
#### **`self.total_send_num: int`**
|
|
66
|
-
|
|
67
|
-
【只读】 总计信号发送次数。
|
|
68
|
-
|
|
69
|
-
#### **`def connect(self, fn: Callable, *, expected_receive_num: int = 0, auto_remove: bool = False)`**
|
|
70
|
-
|
|
71
|
-
通过函数注册响应函数。
|
|
72
|
-
|
|
73
|
-
- **参数**
|
|
74
|
-
|
|
75
|
-
- `expected_receive_num`: 期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
76
|
-
|
|
77
|
-
- `auto_remove`: 是否自动删除响应次数超出期望次数的接收器。
|
|
78
|
-
|
|
79
|
-
- **报错**
|
|
80
|
-
|
|
81
|
-
- `ValueError`: 已有重复的函数接收器。
|
|
82
|
-
|
|
83
|
-
#### **`def connect(self, *, expected_receive_num: int = 0, auto_remove: bool = False)`**
|
|
84
|
-
|
|
85
|
-
通过装饰器注册响应函数。
|
|
86
|
-
|
|
87
|
-
- **参数**
|
|
88
|
-
|
|
89
|
-
- `expected_receive_num`: 期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
90
|
-
|
|
91
|
-
- `auto_remove`: 是否自动删除响应次数超出期望次数的接收器。
|
|
92
|
-
|
|
93
|
-
- **报错**
|
|
94
|
-
|
|
95
|
-
- `ValueError`: 已有重复的函数接收器。
|
|
96
|
-
|
|
97
|
-
#### **`def send(self, *args, **kwargs) -> List[Any]`**
|
|
98
|
-
|
|
99
|
-
发送信号。
|
|
100
|
-
|
|
101
|
-
#### **`async def async_send(self, *args, **kwargs) -> List[Any]`**
|
|
102
|
-
|
|
103
|
-
在协程环境中发送信号,并请保证所有接收函数都是协程函数。
|
|
104
|
-
|
|
105
|
-
```python
|
|
106
|
-
import asyncio
|
|
107
|
-
|
|
108
|
-
from CheeseSignal import Signal
|
|
109
|
-
|
|
110
|
-
async def run_asyncio():
|
|
111
|
-
signal = Signal()
|
|
112
|
-
await signal.async_send('data1', 'data2', **{
|
|
113
|
-
'key1': 'value1',
|
|
114
|
-
'key2': 'value2'
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
asyncio.run(run_asyncio())
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### **`def disconnect(self, fn: Callable)`**
|
|
121
|
-
|
|
122
|
-
断开接收器。
|
|
123
|
-
|
|
124
|
-
```python
|
|
125
|
-
from CheeseSignal import Signal
|
|
126
|
-
|
|
127
|
-
def receiver(*args, **kwargs):
|
|
128
|
-
...
|
|
129
|
-
|
|
130
|
-
signal = Signal()
|
|
131
|
-
signal.connect(receiver)
|
|
132
|
-
signal.disconnect(receiver)
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
- **报错**
|
|
136
|
-
|
|
137
|
-
- `ValueError`: 未找到该函数的接收器。
|
|
138
|
-
|
|
139
|
-
#### **`def reset(self)`**
|
|
140
|
-
|
|
141
|
-
重置统计数据;所有的接收器的统计数据也会同步清空。
|
|
142
|
-
|
|
143
|
-
#### **`def disconnect_all(self)`**
|
|
144
|
-
|
|
145
|
-
断开所有接收器。
|
|
146
|
-
|
|
147
|
-
#### **`def get_receiver(self, fn: Callable) -> Receiver`**
|
|
148
|
-
|
|
149
|
-
获取接收器。
|
|
150
|
-
|
|
151
|
-
```python
|
|
152
|
-
from CheeseSignal import Signal
|
|
153
|
-
|
|
154
|
-
def receiver(*args, **kwargs):
|
|
155
|
-
...
|
|
156
|
-
|
|
157
|
-
signal = Signal()
|
|
158
|
-
signal.connect(receiver)
|
|
159
|
-
|
|
160
|
-
print(signal.get_receiver(receiver))
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
- **报错**
|
|
164
|
-
|
|
165
|
-
- `ValueError`: 未找到该函数的接收器。
|
|
166
|
-
|
|
167
|
-
#### **`def index(self, fn: Callable) -> index`**
|
|
168
|
-
|
|
169
|
-
获取接收器的顺序位置。
|
|
170
|
-
|
|
171
|
-
```python
|
|
172
|
-
from CheeseSignal import Signal
|
|
173
|
-
|
|
174
|
-
def receiver(*args, **kwargs):
|
|
175
|
-
...
|
|
176
|
-
|
|
177
|
-
signal = Signal()
|
|
178
|
-
signal.connect(receiver)
|
|
179
|
-
|
|
180
|
-
print(signal.index(receiver))
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
- **报错**
|
|
184
|
-
|
|
185
|
-
- `ValueError`: 未找到该函数的接收器。
|
|
186
|
-
|
|
187
|
-
### **`class Receiver`**
|
|
188
|
-
|
|
189
|
-
正常使用并不需要手动创建该类。
|
|
190
|
-
|
|
191
|
-
```python
|
|
192
|
-
from CheeseSignal import Receiver
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
#### **`def __init__(self, signal: Signal, fn: Callable, *, expected_receive_num: int, auto_remove: bool)`**
|
|
196
|
-
|
|
197
|
-
- **参数**
|
|
198
|
-
|
|
199
|
-
- `expected_receive_num`: 期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
200
|
-
|
|
201
|
-
- `auto_remove`: 是否自动删除响应次数超出期望次数的接收器。
|
|
202
|
-
|
|
203
|
-
#### **`self.expected_receive_num: int`**
|
|
204
|
-
|
|
205
|
-
期望接受信号的次数,超过该次数则不再响应信号;0为无限次。
|
|
206
|
-
|
|
207
|
-
设置值小于`total_receive_num`且`auto_remove is True`,则会立刻删除。
|
|
208
|
-
|
|
209
|
-
#### **`self.auto_remove: bool`**
|
|
210
|
-
|
|
211
|
-
是否自动删除响应次数超出期望次数的接收器。
|
|
212
|
-
|
|
213
|
-
设置为`True`且`is_expired is True`,则会立刻删除。
|
|
214
|
-
|
|
215
|
-
#### **`self.active: bool`**
|
|
216
|
-
|
|
217
|
-
是否激活;未激活将忽略信号。
|
|
218
|
-
|
|
219
|
-
#### **`self.total_receive_num: int`**
|
|
220
|
-
|
|
221
|
-
【只读】 总计信号接受次数。
|
|
222
|
-
|
|
223
|
-
#### **`self.remaining_receive_num: int`**
|
|
224
|
-
|
|
225
|
-
【只读】 剩余的期望信号接受次数;返回为-1代表无期望信号接受次数。
|
|
226
|
-
|
|
227
|
-
#### **`self.is_expired: bool`**
|
|
228
|
-
|
|
229
|
-
【只读】 是否过期。
|
|
230
|
-
|
|
231
|
-
#### **`self.is_unexpired: bool`**
|
|
232
|
-
|
|
233
|
-
【只读】 是否未过期。
|
|
234
|
-
|
|
235
|
-
#### **`def reset(self)`**
|
|
236
|
-
|
|
237
|
-
重统计置数据。
|
|
238
|
-
|
|
239
|
-
在有期望信号接受次数的情况下,`auto_remove is False`的接收器会重新开始计数并接收信号。
|
|
@@ -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
|