dotask 0.2.3__tar.gz → 0.2.5__tar.gz
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.
- {dotask-0.2.3 → dotask-0.2.5}/PKG-INFO +45 -3
- dotask-0.2.5/README.md +59 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask/util/shell.py +10 -23
- {dotask-0.2.3 → dotask-0.2.5}/dotask.egg-info/PKG-INFO +45 -3
- {dotask-0.2.3 → dotask-0.2.5}/setup.cfg +1 -1
- dotask-0.2.3/README.md +0 -17
- {dotask-0.2.3 → dotask-0.2.5}/LICENSE +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask/__init__.py +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask/task.py +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask/util/__init__.py +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask/util/logger.py +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask.egg-info/SOURCES.txt +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask.egg-info/dependency_links.txt +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/dotask.egg-info/top_level.txt +0 -0
- {dotask-0.2.3 → dotask-0.2.5}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dotask
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: 发布订阅注解方式
|
|
5
5
|
Home-page: https://gitee.com/d-yz/task-manager
|
|
6
6
|
Author: dyz
|
|
@@ -17,7 +17,8 @@ Description-Content-Type: text/markdown
|
|
|
17
17
|
License-File: LICENSE
|
|
18
18
|
Dynamic: license-file
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## 版本说明
|
|
21
|
+
### 0.1.0
|
|
21
22
|
- 在方法上添加@task就可以直接开启一个线程执行任务
|
|
22
23
|
- 常用参数:
|
|
23
24
|
- 生产者: role="producer",topic="自定义"
|
|
@@ -28,9 +29,50 @@ Dynamic: license-file
|
|
|
28
29
|
- subscribe: 对哪些主题感兴趣
|
|
29
30
|
- publish_after: 消费完后继续发布新主题
|
|
30
31
|
- 特别的:方法的返回值可以进行传递,若没有返回值则不会发布新主题(只针对消费者和消费者之间)
|
|
31
|
-
|
|
32
|
+
### 0.2.x
|
|
32
33
|
1. dotask暴露topic_manager=>可以更好的管理生产消费者
|
|
33
34
|
2. 迁移logger至util包下
|
|
34
35
|
3. 添加本地调用shell工具函数->可以很好的适配@task消费者
|
|
35
36
|
1. max_concurrent:控制并发执行的shell数量
|
|
36
37
|
2. 引入dotask.Shell 调用Shell(max_concurrent=?).local_shell_execute(cmd,callback)来使用
|
|
38
|
+
## 快速开始
|
|
39
|
+
### 安装
|
|
40
|
+
`pip install dotask`
|
|
41
|
+
### 示例
|
|
42
|
+
1. 简单的生产发布模式
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
from dotask import task
|
|
46
|
+
from dotask.util import logger
|
|
47
|
+
import random
|
|
48
|
+
|
|
49
|
+
if __name__ == '__main__':
|
|
50
|
+
|
|
51
|
+
@task(role="producer",topic="scan")
|
|
52
|
+
def a():
|
|
53
|
+
return random.randint(1,10)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@task(role="consumer",subscribe="scan",publish_after="sayHi")
|
|
57
|
+
def b(data):
|
|
58
|
+
if data >5:
|
|
59
|
+
return data
|
|
60
|
+
logger.warning(f"本次生成数字:{data},不会继续发布sayHi主题")
|
|
61
|
+
|
|
62
|
+
@task(role="consumer",subscribe="sayHi")
|
|
63
|
+
def c(data):
|
|
64
|
+
logger.debug(f"c触发")
|
|
65
|
+
logger.info(f"消费:{data}")
|
|
66
|
+
//=====================================================================
|
|
67
|
+
2026-02-08 17:30:37 - INFO - 发布主题-[scan]:5
|
|
68
|
+
2026-02-08 17:30:37 - WARNING - 本次生成数字:5,不会继续发布sayHi主题
|
|
69
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:8
|
|
70
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:8
|
|
71
|
+
2026-02-08 17:30:38 - DEBUG - c触发
|
|
72
|
+
2026-02-08 17:30:38 - INFO - 消费:8
|
|
73
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:6
|
|
74
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:6
|
|
75
|
+
2026-02-08 17:30:38 - DEBUG - c触发
|
|
76
|
+
2026-02-08 17:30:38 - INFO - 消费:6
|
|
77
|
+
//======================================================================
|
|
78
|
+
```
|
dotask-0.2.5/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
## 版本说明
|
|
2
|
+
### 0.1.0
|
|
3
|
+
- 在方法上添加@task就可以直接开启一个线程执行任务
|
|
4
|
+
- 常用参数:
|
|
5
|
+
- 生产者: role="producer",topic="自定义"
|
|
6
|
+
- 消费者: role="consumer",subscribe="自定义",publish_after="自定义"
|
|
7
|
+
- 说明:
|
|
8
|
+
- role: 用于区分上下游 producer/consumer
|
|
9
|
+
- topic: 发布的主题
|
|
10
|
+
- subscribe: 对哪些主题感兴趣
|
|
11
|
+
- publish_after: 消费完后继续发布新主题
|
|
12
|
+
- 特别的:方法的返回值可以进行传递,若没有返回值则不会发布新主题(只针对消费者和消费者之间)
|
|
13
|
+
### 0.2.x
|
|
14
|
+
1. dotask暴露topic_manager=>可以更好的管理生产消费者
|
|
15
|
+
2. 迁移logger至util包下
|
|
16
|
+
3. 添加本地调用shell工具函数->可以很好的适配@task消费者
|
|
17
|
+
1. max_concurrent:控制并发执行的shell数量
|
|
18
|
+
2. 引入dotask.Shell 调用Shell(max_concurrent=?).local_shell_execute(cmd,callback)来使用
|
|
19
|
+
## 快速开始
|
|
20
|
+
### 安装
|
|
21
|
+
`pip install dotask`
|
|
22
|
+
### 示例
|
|
23
|
+
1. 简单的生产发布模式
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
from dotask import task
|
|
27
|
+
from dotask.util import logger
|
|
28
|
+
import random
|
|
29
|
+
|
|
30
|
+
if __name__ == '__main__':
|
|
31
|
+
|
|
32
|
+
@task(role="producer",topic="scan")
|
|
33
|
+
def a():
|
|
34
|
+
return random.randint(1,10)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@task(role="consumer",subscribe="scan",publish_after="sayHi")
|
|
38
|
+
def b(data):
|
|
39
|
+
if data >5:
|
|
40
|
+
return data
|
|
41
|
+
logger.warning(f"本次生成数字:{data},不会继续发布sayHi主题")
|
|
42
|
+
|
|
43
|
+
@task(role="consumer",subscribe="sayHi")
|
|
44
|
+
def c(data):
|
|
45
|
+
logger.debug(f"c触发")
|
|
46
|
+
logger.info(f"消费:{data}")
|
|
47
|
+
//=====================================================================
|
|
48
|
+
2026-02-08 17:30:37 - INFO - 发布主题-[scan]:5
|
|
49
|
+
2026-02-08 17:30:37 - WARNING - 本次生成数字:5,不会继续发布sayHi主题
|
|
50
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:8
|
|
51
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:8
|
|
52
|
+
2026-02-08 17:30:38 - DEBUG - c触发
|
|
53
|
+
2026-02-08 17:30:38 - INFO - 消费:8
|
|
54
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:6
|
|
55
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:6
|
|
56
|
+
2026-02-08 17:30:38 - DEBUG - c触发
|
|
57
|
+
2026-02-08 17:30:38 - INFO - 消费:6
|
|
58
|
+
//======================================================================
|
|
59
|
+
```
|
|
@@ -4,34 +4,21 @@ import subprocess
|
|
|
4
4
|
from typing import Optional,Callable
|
|
5
5
|
|
|
6
6
|
class Shell:
|
|
7
|
-
_shell_semaphore:threading.Semaphore = None
|
|
8
|
-
_semaphore_lock = threading.Lock()
|
|
7
|
+
# _shell_semaphore:threading.Semaphore = None
|
|
8
|
+
# _semaphore_lock = threading.Lock()
|
|
9
9
|
|
|
10
|
-
def __init__(self,max_concurrent:int
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
self._shell_semaphore = threading.Semaphore(max_concurrent)
|
|
16
|
-
self._max_concurrent = max_concurrent
|
|
17
|
-
else:
|
|
18
|
-
with Shell._semaphore_lock:
|
|
19
|
-
if Shell._shell_semaphore is None:
|
|
20
|
-
if max_concurrent <= 0:
|
|
21
|
-
raise ValueError("最大并发数必须大于0")
|
|
22
|
-
Shell._shell_semaphore = threading.Semaphore(max_concurrent)
|
|
23
|
-
self._max_concurrent = max_concurrent
|
|
24
|
-
else:
|
|
25
|
-
if Shell._shell_semaphore._value != max_concurrent:
|
|
26
|
-
logger.warning(f"全局信号量已存在(并发数:{Shell._shell_semaphore._value}),忽略传入的max_concurrent={max_concurrent}")
|
|
27
|
-
self._max_concurrent = Shell._shell_semaphore._value
|
|
10
|
+
def __init__(self,max_concurrent:int):
|
|
11
|
+
if max_concurrent <= 0:
|
|
12
|
+
raise ValueError("最大并发数必须大于0")
|
|
13
|
+
self._shell_semaphore = threading.Semaphore(max_concurrent)
|
|
14
|
+
self._max_concurrent = max_concurrent
|
|
28
15
|
|
|
29
16
|
def local_shell_execute(self,cmd:str,callback: Optional[Callable[[bool, str], None]] = None) -> bool:
|
|
30
17
|
def execute_and_wait():
|
|
31
|
-
semaphore = self._shell_semaphore if self.global_sem else Shell._shell_semaphore
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
|
|
20
|
+
with self._shell_semaphore:
|
|
21
|
+
logger.debug(f"实例:{id(self)}-剩余并发名额: {self._shell_semaphore._value} | 开始执行命令: {cmd[:50]}")
|
|
35
22
|
proc = None
|
|
36
23
|
try:
|
|
37
24
|
# 创建并执行命令
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dotask
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: 发布订阅注解方式
|
|
5
5
|
Home-page: https://gitee.com/d-yz/task-manager
|
|
6
6
|
Author: dyz
|
|
@@ -17,7 +17,8 @@ Description-Content-Type: text/markdown
|
|
|
17
17
|
License-File: LICENSE
|
|
18
18
|
Dynamic: license-file
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## 版本说明
|
|
21
|
+
### 0.1.0
|
|
21
22
|
- 在方法上添加@task就可以直接开启一个线程执行任务
|
|
22
23
|
- 常用参数:
|
|
23
24
|
- 生产者: role="producer",topic="自定义"
|
|
@@ -28,9 +29,50 @@ Dynamic: license-file
|
|
|
28
29
|
- subscribe: 对哪些主题感兴趣
|
|
29
30
|
- publish_after: 消费完后继续发布新主题
|
|
30
31
|
- 特别的:方法的返回值可以进行传递,若没有返回值则不会发布新主题(只针对消费者和消费者之间)
|
|
31
|
-
|
|
32
|
+
### 0.2.x
|
|
32
33
|
1. dotask暴露topic_manager=>可以更好的管理生产消费者
|
|
33
34
|
2. 迁移logger至util包下
|
|
34
35
|
3. 添加本地调用shell工具函数->可以很好的适配@task消费者
|
|
35
36
|
1. max_concurrent:控制并发执行的shell数量
|
|
36
37
|
2. 引入dotask.Shell 调用Shell(max_concurrent=?).local_shell_execute(cmd,callback)来使用
|
|
38
|
+
## 快速开始
|
|
39
|
+
### 安装
|
|
40
|
+
`pip install dotask`
|
|
41
|
+
### 示例
|
|
42
|
+
1. 简单的生产发布模式
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
from dotask import task
|
|
46
|
+
from dotask.util import logger
|
|
47
|
+
import random
|
|
48
|
+
|
|
49
|
+
if __name__ == '__main__':
|
|
50
|
+
|
|
51
|
+
@task(role="producer",topic="scan")
|
|
52
|
+
def a():
|
|
53
|
+
return random.randint(1,10)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@task(role="consumer",subscribe="scan",publish_after="sayHi")
|
|
57
|
+
def b(data):
|
|
58
|
+
if data >5:
|
|
59
|
+
return data
|
|
60
|
+
logger.warning(f"本次生成数字:{data},不会继续发布sayHi主题")
|
|
61
|
+
|
|
62
|
+
@task(role="consumer",subscribe="sayHi")
|
|
63
|
+
def c(data):
|
|
64
|
+
logger.debug(f"c触发")
|
|
65
|
+
logger.info(f"消费:{data}")
|
|
66
|
+
//=====================================================================
|
|
67
|
+
2026-02-08 17:30:37 - INFO - 发布主题-[scan]:5
|
|
68
|
+
2026-02-08 17:30:37 - WARNING - 本次生成数字:5,不会继续发布sayHi主题
|
|
69
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:8
|
|
70
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:8
|
|
71
|
+
2026-02-08 17:30:38 - DEBUG - c触发
|
|
72
|
+
2026-02-08 17:30:38 - INFO - 消费:8
|
|
73
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:6
|
|
74
|
+
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:6
|
|
75
|
+
2026-02-08 17:30:38 - DEBUG - c触发
|
|
76
|
+
2026-02-08 17:30:38 - INFO - 消费:6
|
|
77
|
+
//======================================================================
|
|
78
|
+
```
|
dotask-0.2.3/README.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
## 0.1.0
|
|
2
|
-
- 在方法上添加@task就可以直接开启一个线程执行任务
|
|
3
|
-
- 常用参数:
|
|
4
|
-
- 生产者: role="producer",topic="自定义"
|
|
5
|
-
- 消费者: role="consumer",subscribe="自定义",publish_after="自定义"
|
|
6
|
-
- 说明:
|
|
7
|
-
- role: 用于区分上下游 producer/consumer
|
|
8
|
-
- topic: 发布的主题
|
|
9
|
-
- subscribe: 对哪些主题感兴趣
|
|
10
|
-
- publish_after: 消费完后继续发布新主题
|
|
11
|
-
- 特别的:方法的返回值可以进行传递,若没有返回值则不会发布新主题(只针对消费者和消费者之间)
|
|
12
|
-
## 0.2.0
|
|
13
|
-
1. dotask暴露topic_manager=>可以更好的管理生产消费者
|
|
14
|
-
2. 迁移logger至util包下
|
|
15
|
-
3. 添加本地调用shell工具函数->可以很好的适配@task消费者
|
|
16
|
-
1. max_concurrent:控制并发执行的shell数量
|
|
17
|
-
2. 引入dotask.Shell 调用Shell(max_concurrent=?).local_shell_execute(cmd,callback)来使用
|
|
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
|