multiCMD 1.21__py3-none-any.whl → 1.23__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: multiCMD
3
- Version: 1.21
3
+ Version: 1.23
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -0,0 +1,6 @@
1
+ multiCMD.py,sha256=UFv7e7LTyMLWi8VpzPKXxigJT7ldSz5IzRf2q0-CAj8,17352
2
+ multiCMD-1.23.dist-info/METADATA,sha256=6p04p2KcDNUBwIkyigqWozlXLrIJle0U7aGMvhpxuVs,5640
3
+ multiCMD-1.23.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
4
+ multiCMD-1.23.dist-info/entry_points.txt,sha256=nSLBkYrcUCQxt1w3LIJkvgOhpRYEC0xAPqNG7u4OYs8,89
5
+ multiCMD-1.23.dist-info/top_level.txt,sha256=DSqgftD40G09F3qEjpHRCUNUsGUvGZZG69Sm3YEUiWI,9
6
+ multiCMD-1.23.dist-info/RECORD,,
multiCMD.py CHANGED
@@ -18,7 +18,7 @@ import re
18
18
  import itertools
19
19
  import signal
20
20
 
21
- version = '1.21'
21
+ version = '1.23'
22
22
  __version__ = version
23
23
 
24
24
  __running_threads = []
@@ -28,6 +28,7 @@ class Task:
28
28
  self.returncode = None
29
29
  self.stdout = []
30
30
  self.stderr = []
31
+ self.thread = None
31
32
  self.stop = False
32
33
  def __iter__(self):
33
34
  return zip(['command', 'returncode', 'stdout', 'stderr'], [self.command, self.returncode, self.stdout, self.stderr])
@@ -35,6 +36,10 @@ class Task:
35
36
  return f'Task(command={self.command}, returncode={self.returncode}, stdout={self.stdout}, stderr={self.stderr}, stop={self.stop})'
36
37
  def __str__(self):
37
38
  return str(dict(self))
39
+ def is_alive(self):
40
+ if self.thread is not None:
41
+ return self.thread.is_alive()
42
+ return False
38
43
 
39
44
  def _expand_ranges(inStr):
40
45
  '''
@@ -239,19 +244,21 @@ def __run_command(task,sem, timeout=60, quiet=False,dry_run=False,with_stdErr=Fa
239
244
  task.returncode = 137
240
245
  else:
241
246
  task.returncode = -1
242
- if not quiet:
243
- print(pre+'\n'+ '-'*100+post)
244
- print(pre+f'Process exited with return code {task.returncode}'+post)
245
247
  # if file not found
246
248
  except FileNotFoundError as e:
247
- task.stdout.append(f'Command / path not found: {task.command[0]}')
249
+ print(f'Command / path not found: {task.command[0]}',file=sys.stderr,flush=True)
248
250
  task.stderr.append(str(e))
249
251
  task.returncode = 127
250
252
  except Exception as e:
251
253
  import traceback
254
+ print(f'Error running command: {task.command}',file=sys.stderr,flush=True)
255
+ print(str(e).split('\n'))
252
256
  task.stderr.extend(str(e).split('\n'))
253
257
  task.stderr.extend(traceback.format_exc().split('\n'))
254
258
  task.returncode = -1
259
+ if not quiet:
260
+ print(pre+'\n'+ '-'*100+post)
261
+ print(pre+f'Process exited with return code {task.returncode}'+post)
255
262
  if with_stdErr:
256
263
  return task.stdout + task.stderr
257
264
  else:
@@ -348,7 +355,8 @@ def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,wit
348
355
  if max_threads > 1 or not wait_for_return:
349
356
  sem = threading.Semaphore(max_threads) # Limit concurrent sessions
350
357
  threads = [threading.Thread(target=__run_command, args=(task,sem,timeout,quiet,dry_run,...),daemon=True) for task in tasks]
351
- for thread in threads:
358
+ for thread,task in zip(threads,tasks):
359
+ task.thread = thread
352
360
  thread.start()
353
361
  if wait_for_return:
354
362
  for thread in threads:
@@ -525,7 +533,7 @@ def main():
525
533
  parser.add_argument('-q','--quiet', action='store_true',help='quiet mode')
526
534
  parser.add_argument('-V','--version', action='version', version=f'%(prog)s {version} by pan@zopyr.us')
527
535
  args = parser.parse_args()
528
- run_commands(args.commands, args.timeout, args.max_threads, args.quiet,parse = args.parse)
536
+ run_commands(args.commands, args.timeout, args.max_threads, args.quiet,parse = args.parse, with_stdErr=True)
529
537
 
530
538
  if __name__ == '__main__':
531
539
  main()
@@ -1,6 +0,0 @@
1
- multiCMD.py,sha256=d0kwe5KYNJTiR6521NB7UcX_qNwYA3tELWPjL1quYK0,17056
2
- multiCMD-1.21.dist-info/METADATA,sha256=KkZMgNNJXXWGBBzt10MMaOf5Jbx2Yf-itSj5MnEM5wM,5640
3
- multiCMD-1.21.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
4
- multiCMD-1.21.dist-info/entry_points.txt,sha256=nSLBkYrcUCQxt1w3LIJkvgOhpRYEC0xAPqNG7u4OYs8,89
5
- multiCMD-1.21.dist-info/top_level.txt,sha256=DSqgftD40G09F3qEjpHRCUNUsGUvGZZG69Sm3YEUiWI,9
6
- multiCMD-1.21.dist-info/RECORD,,