pyosal 0.2.0__tar.gz → 0.2.2__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.
- {pyosal-0.2.0/src/pyosal.egg-info → pyosal-0.2.2}/PKG-INFO +1 -1
- {pyosal-0.2.0 → pyosal-0.2.2}/pyproject.toml +1 -1
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal/constants_version.py +1 -1
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal/pyosal.py +29 -22
- {pyosal-0.2.0 → pyosal-0.2.2/src/pyosal.egg-info}/PKG-INFO +1 -1
- {pyosal-0.2.0 → pyosal-0.2.2}/LICENSE.txt +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/MANIFEST.in +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/README.md +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/setup.cfg +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal/__init__.py +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal/constants.py +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal.egg-info/SOURCES.txt +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal.egg-info/dependency_links.txt +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal.egg-info/requires.txt +0 -0
- {pyosal-0.2.0 → pyosal-0.2.2}/src/pyosal.egg-info/top_level.txt +0 -0
|
@@ -273,6 +273,7 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
273
273
|
# Run your existing function in a background thread
|
|
274
274
|
shared_container = {}
|
|
275
275
|
t = threading.Thread(target=self.run_cmd, args=(cmd, working_dir, use_raw_log, log_file, print_cb, env, quiet, shared_container))
|
|
276
|
+
t.daemon = True
|
|
276
277
|
t.start()
|
|
277
278
|
|
|
278
279
|
# Wait briefly for the subprocess to actually initialize and populate the container
|
|
@@ -301,7 +302,7 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
301
302
|
timed_out = True
|
|
302
303
|
rc = 0 # override rc since timeout is expected
|
|
303
304
|
|
|
304
|
-
t.join()
|
|
305
|
+
t.join(timeout=0.25)
|
|
305
306
|
rc_str = f'rc={rc}'
|
|
306
307
|
if shared_container['proc'] is None:
|
|
307
308
|
sys.stdout.write(f'[timeout] {rc_str: <6} process ended due to exception\n')
|
|
@@ -326,7 +327,7 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
326
327
|
try:
|
|
327
328
|
rc = self._kill_process_tree(shared_container, 'terminate')
|
|
328
329
|
rc_str = f'rc={rc}'
|
|
329
|
-
|
|
330
|
+
sys.stdout.write(f'[timeout] {rc_str: <6} process terminated gracefully\n')
|
|
330
331
|
except subprocess.TimeoutExpired:
|
|
331
332
|
sys.stdout.write('[timeout] process did not terminate, killing process...\n')
|
|
332
333
|
sys.stdout.flush()
|
|
@@ -457,17 +458,21 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
457
458
|
def _kill_alt_process_tree(self, shared_container):
|
|
458
459
|
rc = 0
|
|
459
460
|
print(f'[timeout] {self.os_name} detected...')
|
|
460
|
-
if '
|
|
461
|
-
cmd_str = ' '.join(shared_container['cmd']
|
|
461
|
+
if 'timed' in self._debug:
|
|
462
|
+
cmd_str = ' '.join(shared_container['cmd'])
|
|
462
463
|
print(f'pyosal._kill_alt_process_tree: pids={shared_container["pids"]} cmd="{cmd_str}"')
|
|
463
464
|
|
|
464
465
|
for pid in shared_container['pids']:
|
|
465
466
|
if not psutil.pid_exists(pid):
|
|
467
|
+
if 'timed' in self._debug:
|
|
468
|
+
print(f'pyosal._kill_alt_process_tree: pid={pid} does not exist')
|
|
466
469
|
continue
|
|
467
470
|
proc = psutil.Process(pid)
|
|
468
|
-
# terminate does not work in windows
|
|
471
|
+
# terminate does not work in windows, must use kill
|
|
469
472
|
proc.kill()
|
|
470
|
-
|
|
473
|
+
if 'timed' in self._debug:
|
|
474
|
+
print(f'pyosal._kill_alt_process_tree: pid={pid} killed')
|
|
475
|
+
time.sleep(0.100)
|
|
471
476
|
return rc
|
|
472
477
|
|
|
473
478
|
# -------------------
|
|
@@ -512,7 +517,7 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
512
517
|
## kill a POSIX process
|
|
513
518
|
# @param pid the process id to kill
|
|
514
519
|
# @param action "terminate" to ask process to terminate itself.
|
|
515
|
-
#
|
|
520
|
+
# "kill" to terminate the process externally
|
|
516
521
|
# @return None
|
|
517
522
|
def _kill_process(self, pid, action):
|
|
518
523
|
try:
|
|
@@ -528,6 +533,9 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
528
533
|
cmd = ['sudo', 'kill', '-9' if action == 'kill' else '-15', str(pid.pid)]
|
|
529
534
|
subprocess.run(cmd, check=False)
|
|
530
535
|
|
|
536
|
+
# give it time to clean up
|
|
537
|
+
time.sleep(0.100)
|
|
538
|
+
|
|
531
539
|
# -------------------
|
|
532
540
|
## run a command in a subprocess
|
|
533
541
|
#
|
|
@@ -585,7 +593,6 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
585
593
|
universal_newlines=True,
|
|
586
594
|
errors='replace',
|
|
587
595
|
text=True,
|
|
588
|
-
# stdin=subprocess.DEVNULL,
|
|
589
596
|
stdin=None,
|
|
590
597
|
stdout=subprocess.PIPE,
|
|
591
598
|
stderr=subprocess.STDOUT,
|
|
@@ -612,30 +619,31 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
612
619
|
shared_container['state'] = 'cmd-not-found'
|
|
613
620
|
|
|
614
621
|
# buffer contains the current set of bytes read from proc.stdout so far
|
|
615
|
-
buffer =
|
|
622
|
+
buffer = ''
|
|
616
623
|
while True:
|
|
617
|
-
|
|
618
|
-
if not
|
|
624
|
+
char = proc.stdout.read(1)
|
|
625
|
+
if not char:
|
|
626
|
+
# it's ''
|
|
619
627
|
break
|
|
620
628
|
|
|
621
629
|
# append the current chunk
|
|
622
630
|
# Some apps use linefeeds to do "progress" lines (e.g. 10% 11% etc), so replace any linefeeds with nothing
|
|
623
|
-
|
|
631
|
+
if char == '\r':
|
|
632
|
+
char = '\n'
|
|
633
|
+
|
|
634
|
+
buffer += char
|
|
624
635
|
|
|
625
|
-
# if there
|
|
626
|
-
if
|
|
636
|
+
# if there is a newline in the buffer, then we have at least a full line of characters
|
|
637
|
+
if '\n' not in buffer:
|
|
627
638
|
continue
|
|
628
639
|
|
|
629
640
|
# split the buffer at the newline(s)
|
|
630
|
-
buff_lines = buffer.split(
|
|
641
|
+
buff_lines = buffer.split('\n')
|
|
631
642
|
# save the remaining bytes in buffer
|
|
632
643
|
buffer = buff_lines.pop()
|
|
633
644
|
|
|
634
645
|
# at this point buff_lines contains one or more lines (as bytes)
|
|
635
|
-
for
|
|
636
|
-
# convert the bytes to UTF-8 chars
|
|
637
|
-
line = line_bytes.decode('utf-8', errors='replace')
|
|
638
|
-
|
|
646
|
+
for line in buff_lines:
|
|
639
647
|
if 'run' in self._debug:
|
|
640
648
|
if not line.isprintable():
|
|
641
649
|
sys.stdout.write('has hex: ' + ascii(line) + '\n')
|
|
@@ -668,10 +676,9 @@ class PyOsal(metaclass=_PyOsalMeta):
|
|
|
668
676
|
|
|
669
677
|
# at this point: chunk was empty
|
|
670
678
|
if len(buffer) > 0:
|
|
671
|
-
|
|
672
|
-
for
|
|
679
|
+
lines = buffer.split('\n')
|
|
680
|
+
for line in lines:
|
|
673
681
|
lineno += 1
|
|
674
|
-
line = line_bytes.decode('utf-8', errors='replace')
|
|
675
682
|
self._save_line(line, lineno, lines, fp, print_cb, use_raw_log, quiet)
|
|
676
683
|
|
|
677
684
|
if fp:
|
|
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
|