multiCMD 1.17__tar.gz → 1.18__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.17
3
+ Version: 1.18
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.17
3
+ Version: 1.18
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -10,8 +10,9 @@ import os
10
10
  import string
11
11
  import re
12
12
  import itertools
13
+ import signal
13
14
 
14
- version = '1.17'
15
+ version = '1.18'
15
16
  __version__ = version
16
17
 
17
18
  __running_threads = []
@@ -21,10 +22,11 @@ class Task:
21
22
  self.returncode = None
22
23
  self.stdout = []
23
24
  self.stderr = []
25
+ self.stop = False
24
26
  def __iter__(self):
25
27
  return zip(['command', 'returncode', 'stdout', 'stderr'], [self.command, self.returncode, self.stdout, self.stderr])
26
28
  def __repr__(self):
27
- return f'Task(command={self.command}, returncode={self.returncode}, stdout={self.stdout}, stderr={self.stderr})'
29
+ return f'Task(command={self.command}, returncode={self.returncode}, stdout={self.stdout}, stderr={self.stderr}, stop={self.stop})'
28
30
  def __str__(self):
29
31
  return str(dict(self))
30
32
 
@@ -194,13 +196,21 @@ def __run_command(task,sem, timeout=60, quiet=False,dry_run=False,with_stdErr=Fa
194
196
  time.sleep(0)
195
197
  sleep_time = 1.0e-8 # 10 nanoseconds
196
198
  while proc.poll() is None: # while the process is still running
197
- if len(task.stdout) + len(task.stderr) != outLength:
198
- start_time = time.time()
199
- outLength = len(task.stdout) + len(task.stderr)
200
- if timeout > 0 and time.time() - start_time > timeout:
201
- task.stderr.append('Timeout!')
199
+ if task.stop:
200
+ proc.send_signal(signal.SIGINT)
201
+ time.sleep(0.01)
202
202
  proc.terminate()
203
203
  break
204
+ if timeout > 0:
205
+ if len(task.stdout) + len(task.stderr) != outLength:
206
+ start_time = time.time()
207
+ outLength = len(task.stdout) + len(task.stderr)
208
+ elif time.time() - start_time > timeout:
209
+ task.stderr.append('Timeout!')
210
+ proc.send_signal(signal.SIGINT)
211
+ time.sleep(0.01)
212
+ proc.terminate()
213
+ break
204
214
  time.sleep(sleep_time)
205
215
  # exponential backoff
206
216
  if sleep_time < 0.001:
@@ -215,7 +225,8 @@ def __run_command(task,sem, timeout=60, quiet=False,dry_run=False,with_stdErr=Fa
215
225
  __handle_stream(io.BytesIO(stdout),task.stdout, task)
216
226
  if stderr:
217
227
  __handle_stream(io.BytesIO(stderr),task.stderr, task)
218
- task.returncode = proc.poll()
228
+ if task.returncode is None:
229
+ task.returncode = -1
219
230
  if not quiet:
220
231
  print(pre+'\n'+ '-'*100+post)
221
232
  print(pre+f'Process exited with return code {task.returncode}'+post)
File without changes
File without changes
File without changes