Skip to content

Commit

Permalink
eliminate usage of pylib
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Oct 29, 2022
1 parent 9b49699 commit 2c39101
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
from subprocess import PIPE
from subprocess import Popen

from py._path.local import LocalPath


# these signals cause dumb-init to suspend itself
SUSPEND_SIGNALS = frozenset([
signal.SIGTSTP,
Expand Down Expand Up @@ -49,9 +46,10 @@ def print_signals(args=()):
def child_pids(pid):
"""Return a list of direct child PIDs for the given PID."""
children = set()
for p in LocalPath('/proc').listdir():
for p in os.listdir('/proc'):
try:
stat = open(p.join('stat').strpath).read()
with open(os.path.join('/proc', p, 'stat')) as f:
stat = f.read()
m = re.match(
r'^\d+ \(.+?\) '
# This field, state, is normally a single letter, but can be
Expand All @@ -65,7 +63,7 @@ def child_pids(pid):
assert m, stat
ppid = int(m.group(1))
if ppid == pid:
children.add(int(p.basename))
children.add(int(p))
except OSError:
# Happens when the process exits after listing it, or between
# opening stat and reading it.
Expand All @@ -85,12 +83,13 @@ def pid_tree(pid):

def is_alive(pid):
"""Return whether a process is running with the given PID."""
return LocalPath('/proc').join(str(pid)).isdir()
return os.path.isdir(os.path.join('/proc', str(pid)))


def process_state(pid):
"""Return a process' state, such as "stopped" or "running"."""
status = LocalPath('/proc').join(str(pid), 'status').read()
with open(os.path.join('/proc', str(pid), 'status')) as f:
status = f.read()
m = re.search(r'^State:\s+[A-Z] \(([a-z]+)\)$', status, re.MULTILINE)
return m.group(1)

Expand Down

0 comments on commit 2c39101

Please sign in to comment.