pyosal 0.2.0__tar.gz → 0.2.1__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.1
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.1'
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.1'
@@ -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,16 +458,20 @@ 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
471
  # terminate does not work in windows
469
472
  proc.kill()
473
+ if 'timed' in self._debug:
474
+ print(f'pyosal._kill_alt_process_tree: pid={pid} killed')
470
475
  time.sleep(0.010)
471
476
  return rc
472
477
 
@@ -585,7 +590,6 @@ class PyOsal(metaclass=_PyOsalMeta):
585
590
  universal_newlines=True,
586
591
  errors='replace',
587
592
  text=True,
588
- # stdin=subprocess.DEVNULL,
589
593
  stdin=None,
590
594
  stdout=subprocess.PIPE,
591
595
  stderr=subprocess.STDOUT,
@@ -612,30 +616,31 @@ class PyOsal(metaclass=_PyOsalMeta):
612
616
  shared_container['state'] = 'cmd-not-found'
613
617
 
614
618
  # buffer contains the current set of bytes read from proc.stdout so far
615
- buffer = b''
619
+ buffer = ''
616
620
  while True:
617
- chunk = os.read(proc.stdout.fileno(), 256)
618
- if not chunk:
621
+ char = proc.stdout.read(1)
622
+ if not char:
623
+ # it's ''
619
624
  break
620
625
 
621
626
  # append the current chunk
622
627
  # 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'')
628
+ if char == '\r':
629
+ char = '\n'
624
630
 
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:
631
+ buffer += char
632
+
633
+ # if there is a newline in the buffer, then we have at least a full line of characters
634
+ if '\n' not in buffer:
627
635
  continue
628
636
 
629
637
  # split the buffer at the newline(s)
630
- buff_lines = buffer.split(b'\n')
638
+ buff_lines = buffer.split('\n')
631
639
  # save the remaining bytes in buffer
632
640
  buffer = buff_lines.pop()
633
641
 
634
642
  # 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
-
643
+ for line in buff_lines:
639
644
  if 'run' in self._debug:
640
645
  if not line.isprintable():
641
646
  sys.stdout.write('has hex: ' + ascii(line) + '\n')
@@ -668,10 +673,9 @@ class PyOsal(metaclass=_PyOsalMeta):
668
673
 
669
674
  # at this point: chunk was empty
670
675
  if len(buffer) > 0:
671
- buff_lines = buffer.split(b'\n')
672
- for line_bytes in buff_lines:
676
+ lines = buffer.split('\n')
677
+ for line in lines:
673
678
  lineno += 1
674
- line = line_bytes.decode('utf-8', errors='replace')
675
679
  self._save_line(line, lineno, lines, fp, print_cb, use_raw_log, quiet)
676
680
 
677
681
  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.1
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