multiCMD 1.28__tar.gz → 1.30__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: multiCMD
3
- Version: 1.28
3
+ Version: 1.30
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiCMD
3
- Version: 1.28
3
+ Version: 1.30
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -18,10 +18,11 @@ import re
18
18
  import itertools
19
19
  import signal
20
20
 
21
- version = '1.28'
21
+ version = '1.30'
22
22
  __version__ = version
23
23
 
24
24
  __running_threads = []
25
+ __variables = {}
25
26
  class Task:
26
27
  def __init__(self, command):
27
28
  self.command = command
@@ -42,7 +43,7 @@ class Task:
42
43
  return False
43
44
 
44
45
  class AsyncExecutor:
45
- def __init__(self, max_threads=1,semaphore=None,timeout=0,quiet=True,dry_run=False,parse=False):
46
+ def __init__(self, max_threads=1,semaphore=...,timeout=0,quiet=True,dry_run=False,parse=False):
46
47
  '''
47
48
  AsyncExecutor class to run commands in parallel asynchronously
48
49
  @params:
@@ -54,6 +55,8 @@ class AsyncExecutor:
54
55
  parse: Whether to parse ranged input ( bool )
55
56
  '''
56
57
  self.max_threads = max_threads
58
+ if semaphore is ...:
59
+ semaphore = threading.Semaphore(max_threads)
57
60
  self.semaphore = semaphore
58
61
  self.runningThreads = []
59
62
  self.tasks = []
@@ -61,6 +64,7 @@ class AsyncExecutor:
61
64
  self.quiet = quiet
62
65
  self.dry_run = dry_run
63
66
  self.parse = parse
67
+ self.__lastNotJoined = 0
64
68
 
65
69
  def __iter__(self):
66
70
  return iter(self.tasks)
@@ -103,6 +107,15 @@ class AsyncExecutor:
103
107
  parse = self.parse
104
108
  if sem is ...:
105
109
  sem = self.semaphore
110
+ if len(self.runningThreads) > 130000:
111
+ self.wait(timeout=0)
112
+ if len(self.runningThreads) > 130000:
113
+ print('The amount of running threads approching cpython limit of 130704. Waiting until some available.')
114
+ while len(self.runningThreads) > 120000:
115
+ self.wait(timeout=1)
116
+ elif len(self.runningThreads) + self.__lastNotJoined > 1000:
117
+ self.wait(timeout=0)
118
+ self.__lastNotJoined = len(self.runningThreads)
106
119
  taskObjects: list[Task] = run_commands(commands,timeout=timeout,max_threads=max_threads,quiet=quiet,dry_run=dry_run,with_stdErr=False,
107
120
  return_code_only=False,return_object=True, parse = parse, wait_for_return = False, sem = sem)
108
121
  self.tasks.extend(taskObjects)
@@ -139,7 +152,7 @@ class AsyncExecutor:
139
152
  if timeout is ...:
140
153
  timeout = self.timeout
141
154
  for thread in threads:
142
- if timeout > 0:
155
+ if timeout >= 0:
143
156
  thread.join(timeout=timeout)
144
157
  else:
145
158
  thread.join()
@@ -224,6 +237,7 @@ def _expand_ranges(inStr):
224
237
  @returns:
225
238
  list[str]: The expanded string
226
239
  '''
240
+ global __variables
227
241
  expandingStr = [inStr]
228
242
  expandedList = []
229
243
  # all valid alphanumeric characters
@@ -238,14 +252,22 @@ def _expand_ranges(inStr):
238
252
  parts = group.split(',')
239
253
  for part in parts:
240
254
  part = part.strip()
241
- if '-' in part:
255
+ if ':' in part:
256
+ variableName, _, part = part.partition(':')
257
+ __variables[variableName] = part
258
+ expandingStr.append(currentStr.replace(match.group(0), '', 1))
259
+ elif '-' in part:
242
260
  try:
243
261
  range_start,_, range_end = part.partition('-')
244
262
  except ValueError:
245
263
  expandedList.append(currentStr)
246
264
  continue
247
265
  range_start = range_start.strip()
266
+ if range_start in __variables:
267
+ range_start = __variables[range_start]
248
268
  range_end = range_end.strip()
269
+ if range_end in __variables:
270
+ range_end = __variables[range_end]
249
271
  if range_start.isdigit() and range_end.isdigit():
250
272
  padding_length = min(len(range_start), len(range_end))
251
273
  format_str = "{:0" + str(padding_length) + "d}"
File without changes
File without changes
File without changes