def get_absolute_path(event_raw):
'''
Keeps a cache of processes' cwds, in case that their events might come
after they're terminated.
'''
pid = event_raw.get('pid')
path = event_raw.get('path')
if path and path[0] == '/':
return os.path.realpath(path)
cwd = None
logger.debug('%r' % pid_cwd)
try:
process = psutil.Process(pid)
cwd = process.cwd()
pid_cwd[pid] = cwd # cache every pid's cwd
except (psutil.NoSuchProcess, psutil.AccessDenied):
cwd = pid_cwd.get(pid)
if not cwd:
return None
return os.path.realpath(os.path.join(cwd, path))
评论列表
文章目录