Skip to content

Commit b1a2551

Browse files
authored
Merge pull request #288 from asottile/eliminate-pylib
eliminate usage of pylib
2 parents 9b49699 + 2c39101 commit b1a2551

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

testing/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
from subprocess import PIPE
99
from subprocess import Popen
1010

11-
from py._path.local import LocalPath
12-
13-
1411
# these signals cause dumb-init to suspend itself
1512
SUSPEND_SIGNALS = frozenset([
1613
signal.SIGTSTP,
@@ -49,9 +46,10 @@ def print_signals(args=()):
4946
def child_pids(pid):
5047
"""Return a list of direct child PIDs for the given PID."""
5148
children = set()
52-
for p in LocalPath('/proc').listdir():
49+
for p in os.listdir('/proc'):
5350
try:
54-
stat = open(p.join('stat').strpath).read()
51+
with open(os.path.join('/proc', p, 'stat')) as f:
52+
stat = f.read()
5553
m = re.match(
5654
r'^\d+ \(.+?\) '
5755
# This field, state, is normally a single letter, but can be
@@ -65,7 +63,7 @@ def child_pids(pid):
6563
assert m, stat
6664
ppid = int(m.group(1))
6765
if ppid == pid:
68-
children.add(int(p.basename))
66+
children.add(int(p))
6967
except OSError:
7068
# Happens when the process exits after listing it, or between
7169
# opening stat and reading it.
@@ -85,12 +83,13 @@ def pid_tree(pid):
8583

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

9088

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

0 commit comments

Comments
 (0)