eliminate usage of pylib
This commit is contained in:
parent
9b49699976
commit
2c39101849
1 changed files with 7 additions and 8 deletions
|
@ -8,9 +8,6 @@ from contextlib import contextmanager
|
||||||
from subprocess import PIPE
|
from subprocess import PIPE
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
from py._path.local import LocalPath
|
|
||||||
|
|
||||||
|
|
||||||
# these signals cause dumb-init to suspend itself
|
# these signals cause dumb-init to suspend itself
|
||||||
SUSPEND_SIGNALS = frozenset([
|
SUSPEND_SIGNALS = frozenset([
|
||||||
signal.SIGTSTP,
|
signal.SIGTSTP,
|
||||||
|
@ -49,9 +46,10 @@ def print_signals(args=()):
|
||||||
def child_pids(pid):
|
def child_pids(pid):
|
||||||
"""Return a list of direct child PIDs for the given PID."""
|
"""Return a list of direct child PIDs for the given PID."""
|
||||||
children = set()
|
children = set()
|
||||||
for p in LocalPath('/proc').listdir():
|
for p in os.listdir('/proc'):
|
||||||
try:
|
try:
|
||||||
stat = open(p.join('stat').strpath).read()
|
with open(os.path.join('/proc', p, 'stat')) as f:
|
||||||
|
stat = f.read()
|
||||||
m = re.match(
|
m = re.match(
|
||||||
r'^\d+ \(.+?\) '
|
r'^\d+ \(.+?\) '
|
||||||
# This field, state, is normally a single letter, but can be
|
# This field, state, is normally a single letter, but can be
|
||||||
|
@ -65,7 +63,7 @@ def child_pids(pid):
|
||||||
assert m, stat
|
assert m, stat
|
||||||
ppid = int(m.group(1))
|
ppid = int(m.group(1))
|
||||||
if ppid == pid:
|
if ppid == pid:
|
||||||
children.add(int(p.basename))
|
children.add(int(p))
|
||||||
except OSError:
|
except OSError:
|
||||||
# Happens when the process exits after listing it, or between
|
# Happens when the process exits after listing it, or between
|
||||||
# opening stat and reading it.
|
# opening stat and reading it.
|
||||||
|
@ -85,12 +83,13 @@ def pid_tree(pid):
|
||||||
|
|
||||||
def is_alive(pid):
|
def is_alive(pid):
|
||||||
"""Return whether a process is running with the given 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):
|
def process_state(pid):
|
||||||
"""Return a process' state, such as "stopped" or "running"."""
|
"""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)
|
m = re.search(r'^State:\s+[A-Z] \(([a-z]+)\)$', status, re.MULTILINE)
|
||||||
return m.group(1)
|
return m.group(1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue