Skip to content

Hua work common#108

Merged
zaihuaji merged 4 commits into
mainfrom
hua-work-common
May 19, 2026
Merged

Hua work common#108
zaihuaji merged 4 commits into
mainfrom
hua-work-common

Conversation

@zaihuaji
Copy link
Copy Markdown
Collaborator

No description provided.

zaihuaji and others added 3 commits May 19, 2026 13:57
Eliminates subprocess spawns for common hot paths:
- pg_sig.py: ps/os.system calls replaced with os.kill, psutil
  process iteration, and subprocess.Popen for the background launcher
- pg_log.py: grep /etc/passwd -> pwd.getpwnam; os.system('more') ->
  subprocess.run (avoids shell-quoting on the filename)
- pg_file.py: md5sum subprocess -> hashlib.md5 chunked read

Adds psutil as a dependency in pyproject.toml and requirements.txt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 19, 2026 19:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes several OS-level interactions in rda_python_common by replacing shell command pipelines (e.g., ps, grep, md5sum, more) with Python-native implementations (psutil, hashlib, subprocess) and bumps the package version to 2.1.11.

Changes:

  • Replace ps/grep-based process discovery and child enumeration with psutil in PgSIG.
  • Replace md5sum subprocess calls with a streaming hashlib.md5() implementation in PgFile.
  • Update usage display and specialist home lookup logic to avoid shelling out (more, /etc/passwd parsing), plus dependency/version bumps.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/rda_python_common/pg_sig.py Switch process scanning/child management/background start to psutil + subprocess.
src/rda_python_common/pg_log.py Replace os.system("more ...") with subprocess.run, and use pwd.getpwnam for specialist home/shell.
src/rda_python_common/pg_file.py Implement MD5 calculation in Python via hashlib instead of md5sum.
src/rda_python_common/__init__.py Bump __version__ to 2.1.11.
requirements.txt Add psutil dependency.
README.md Update referenced version to 2.1.11.
pyproject.toml Bump project version and add psutil to dependencies.
Comments suppressed due to low confidence (1)

src/rda_python_common/pg_sig.py:825

  • check_process() treats any OSError from os.kill(pid, 0) as “not running”. On POSIX, EPERM means the process exists but you don’t have permission to signal it, so this will incorrectly report live processes as dead. Handle PermissionError/errno.EPERM as running and only return 0 for ProcessLookupError/errno.ESRCH (and possibly treat other errors conservatively/log them).
      try:
         os.kill(pid, 0)
      except OSError:
         return 0
      return 1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +232 to +239
if not any(aname in arg for arg in cmdline): continue
else:
exe = os.path.basename(cmdline[0])
if exe != aname and re.sub(r'\.\w+$', '', exe) != aname: continue
results.append({
'pid': info['pid'],
'ppid': info['ppid'],
'args': ' '.join(cmdline[1:]),
# shell=True is required for the redirections (>> / 2>>) and trailing '&';
# the '&' makes the shell fork the command and exit, so the command gets
# reparented to init (ppid=1), matching the lookup logic in record_background().
subprocess.Popen(bckcmd, shell=True)
Comment on lines 772 to 774
else:
os.system("more " + usgname)
subprocess.run(['more', usgname])
self.pgexit(0)
@zaihuaji zaihuaji merged commit 6464ec5 into main May 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants