dotask 0.2.2__tar.gz → 0.2.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dotask
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: 发布订阅注解方式
5
5
  Home-page: https://gitee.com/d-yz/task-manager
6
6
  Author: dyz
@@ -7,20 +7,31 @@ class Shell:
7
7
  _shell_semaphore:threading.Semaphore = None
8
8
  _semaphore_lock = threading.Lock()
9
9
 
10
- def __init__(self,max_concurrent:int):
11
- with Shell._semaphore_lock:
12
- if Shell._shell_semaphore is None:
13
- if max_concurrent <= 0:
14
- raise ValueError("最大并发数必须大于0")
15
- Shell._shell_semaphore = threading.Semaphore(max_concurrent)
16
- self._max_concurrent = max_concurrent
17
- else:
18
- self._max_concurrent = Shell._shell_semaphore._value
10
+ def __init__(self,max_concurrent:int,global_sem=False):
11
+ self.global_sem = global_sem
12
+ if global_sem:
13
+ if max_concurrent <= 0:
14
+ raise ValueError("最大并发数必须大于0")
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
19
28
 
20
29
  def local_shell_execute(self,cmd:str,callback: Optional[Callable[[bool, str], None]] = None) -> bool:
21
30
  def execute_and_wait():
22
- with Shell._shell_semaphore:
23
- logger.debug(f"剩余并发名额: {Shell._shell_semaphore._value} | 开始执行命令: {cmd[:50]}")
31
+ semaphore = self._shell_semaphore if self.global_sem else Shell._shell_semaphore
32
+
33
+ with semaphore:
34
+ logger.debug(f"实例:{id(self)}-剩余并发名额: {semaphore._value} | 开始执行命令: {cmd[:50]}")
24
35
  proc = None
25
36
  try:
26
37
  # 创建并执行命令
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dotask
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: 发布订阅注解方式
5
5
  Home-page: https://gitee.com/d-yz/task-manager
6
6
  Author: dyz
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = dotask
3
- version = 0.2.2
3
+ version = 0.2.3
4
4
  author = dyz
5
5
  author_email = 837701454@qq.com
6
6
  description = 发布订阅注解方式
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes