From 2c39101849abb835e9f368e3cf5c9570362a9589 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 29 Oct 2022 17:56:35 -0400 Subject: [PATCH] eliminate usage of pylib --- testing/__init__.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/testing/__init__.py b/testing/__init__.py index 80a4c66..e860e09 100644 --- a/testing/__init__.py +++ b/testing/__init__.py @@ -8,9 +8,6 @@ from contextlib import contextmanager 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, @@ -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 @@ -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. @@ -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)