Skip to content

Commit

Permalink
Finally fixed psutil issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
wnielson committed Jul 14, 2016
1 parent 48bd2b0 commit 13ae24d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions prt.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,23 +370,28 @@ def get_sessions():
plex_sessions = get_plex_sessions()

for proc in psutil.process_iter():
parent = None
if callable(proc.parent):
parent = proc.parent()
else:
parent = proc.parent
parent_name = None
try:
if callable(proc.parent):
parent_name = proc.parent().name()
else:
parent_name = proc.parent.name
except:
continue

if not parent or not hasattr(parent, 'name'):
if not parent_name:
continue

pinfo = proc.as_dict(['name', 'cmdline'])

# Check the parent to make sure it is the "Plex Transcoder"
if proc.name == 'ssh' and 'plex' in parent.name.lower():
cmdline = ' '.join(proc.cmdline)
if pinfo['name'] == 'ssh' and 'plex' in parent_name.lower():
cmdline = ' '.join(pinfo['cmdline'])
m = PRT_ID_RE.search(cmdline)
if m:
session_id = re_get(SESSION_RE, cmdline)
data = {
'proc': proc,
'proc': pinfo,
'plex': plex_sessions.get(session_id, {}),
'host': {}
}
Expand All @@ -401,7 +406,6 @@ def get_sessions():
sessions[m.groups()[0]] = data
return sessions


def sessions():
if psutil is None:
print "Missing required library 'psutil'. Try 'pip install psutil'."
Expand Down

0 comments on commit 13ae24d

Please sign in to comment.