multiCMD 1.22__tar.gz → 1.24__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.2
2
2
  Name: multiCMD
3
- Version: 1.22
3
+ Version: 1.24
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.2
2
2
  Name: multiCMD
3
- Version: 1.22
3
+ Version: 1.24
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -18,7 +18,7 @@ import re
18
18
  import itertools
19
19
  import signal
20
20
 
21
- version = '1.22'
21
+ version = '1.24'
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
  '''
@@ -259,6 +264,31 @@ def __run_command(task,sem, timeout=60, quiet=False,dry_run=False,with_stdErr=Fa
259
264
  else:
260
265
  return task.stdout
261
266
 
267
+ def ping(hosts,timeout=1,max_threads=0,quiet=True,dry_run=False,with_stdErr=False,
268
+ return_code_only=True,return_object=False,wait_for_return=True):
269
+ '''
270
+ Ping multiple hosts
271
+
272
+ @params:
273
+ hosts: The hosts to ping
274
+ timeout: The timeout for the command
275
+ max_threads: The maximum number of threads to use
276
+ quiet: Whether to suppress output
277
+ dry_run: Whether to simulate running the command
278
+ with_stdErr: Whether to append the standard error output to the standard output
279
+ return_code_only: Whether to return only the return code
280
+ return_object: Whether to return the Task object
281
+ wait_for_return: Whether to wait for the return of the command
282
+
283
+ @returns:
284
+ None | int | list[str] | Task: The output of the command
285
+ '''
286
+ commands = [f'ping -c 1 {host}' for host in hosts]
287
+ return run_commands(commands, timeout=timeout, max_threads=max_threads, quiet=quiet,
288
+ dry_run=dry_run, with_stdErr=with_stdErr, return_code_only=return_code_only,
289
+ return_object=return_object,wait_for_return=wait_for_return)
290
+
291
+
262
292
  def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
263
293
  return_code_only=False,return_object=False,wait_for_return=True):
264
294
  '''
@@ -350,7 +380,8 @@ def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,wit
350
380
  if max_threads > 1 or not wait_for_return:
351
381
  sem = threading.Semaphore(max_threads) # Limit concurrent sessions
352
382
  threads = [threading.Thread(target=__run_command, args=(task,sem,timeout,quiet,dry_run,...),daemon=True) for task in tasks]
353
- for thread in threads:
383
+ for thread,task in zip(threads,tasks):
384
+ task.thread = thread
354
385
  thread.start()
355
386
  if wait_for_return:
356
387
  for thread in threads:
File without changes
File without changes
File without changes