dotask 0.2.4__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.4 → dotask-0.2.5}/PKG-INFO +1 -1
- {dotask-0.2.4 → dotask-0.2.5}/dotask/util/shell.py +10 -23
- {dotask-0.2.4 → dotask-0.2.5}/dotask.egg-info/PKG-INFO +1 -1
- {dotask-0.2.4 → dotask-0.2.5}/setup.cfg +1 -1
- {dotask-0.2.4 → dotask-0.2.5}/LICENSE +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/README.md +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/dotask/__init__.py +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/dotask/task.py +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/dotask/util/__init__.py +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/dotask/util/logger.py +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/dotask.egg-info/SOURCES.txt +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/dotask.egg-info/dependency_links.txt +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/dotask.egg-info/top_level.txt +0 -0
- {dotask-0.2.4 → dotask-0.2.5}/pyproject.toml +0 -0
|
@@ -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
|
# 创建并执行命令
|
|
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
|
|
File without changes
|