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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyosal
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: python Operating System Abstract Layer
5
5
  Author-email: "J. Arrizza" <cppgent0@gmail.com>
6
6
  Maintainer-email: "J. Arrizza" <cppgent0@gmail.com>
@@ -19,7 +19,7 @@ dependencies = [
19
19
 
20
20
  # common values
21
21
  name = 'pyosal'
22
- version = '0.2.0'
22
+ version = '0.2.2'
23
23
  requires-python = '>=3.9'
24
24
  authors = [{ name = 'J. Arrizza', email = 'cppgent0@gmail.com' }]
25
25
  maintainers = [
@@ -6,4 +6,4 @@ from dataclasses import dataclass
6
6
  @dataclass
7
7
  class ConstantsVersion:
8
8
  ## current App version
9
- version = '0.2.0'
9
+ version = '0.2.2'
@@ -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
- print(f'[timeout] {rc_str: <6} process terminated gracefully')
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 'timer' in self._debug:
461
- cmd_str = ' '.join(shared_container['cmd'][2:])
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
- time.sleep(0.010)
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
- # "kill" to terminate the process externally
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 = b''
622
+ buffer = ''
616
623
  while True:
617
- chunk = os.read(proc.stdout.fileno(), 256)
618
- if not chunk:
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
- buffer += chunk.replace(b'\r', b'')
631
+ if char == '\r':
632
+ char = '\n'
633
+
634
+ buffer += char
624
635
 
625
- # if there was a newline in the buffer, then we have at least a full line of characters
626
- if b'\n' not in buffer:
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(b'\n')
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 line_bytes in buff_lines:
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
- buff_lines = buffer.split(b'\n')
672
- for line_bytes in buff_lines:
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyosal
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: python Operating System Abstract Layer
5
5
  Author-email: "J. Arrizza" <cppgent0@gmail.com>
6
6
  Maintainer-email: "J. Arrizza" <cppgent0@gmail.com>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes