Make psutil features of our fedmsg config optional for mod_wsgi on rhel7.

This commit is contained in:
Ralph Bean 2014-07-04 04:35:27 +00:00
parent 3f6fb1677f
commit 51e097143c
2 changed files with 28 additions and 8 deletions

View file

@ -4,10 +4,18 @@
import inspect
import logging
import os
import psutil
import socket
import traceback
psutil = None
try:
import psutil
except OSError:
# We run into issues when trying to import psutil from inside mod_wsgi on
# rhel7. If we hit that here, then just fail quietly.
# https://github.com/jmflinuxtx/kerneltest-harness/pull/17#issuecomment-48007837
pass
class ContextInjector(logging.Filter):
""" Logging filter that adds context to log records.
@ -57,6 +65,10 @@ class ContextInjector(logging.Filter):
@staticmethod
def get_current_process():
mypid = os.getpid()
if not psutil:
raise OSError("Could not import psutil for %r" % mypid)
for proc in psutil.process_iter():
if proc.pid == mypid:
return proc