Made uwsgi pids retrieval compatible with psutil>2.0.0
Also added some logging and cleaned code Change-Id: Icd5f239d346d2e7120ce000dc500cde09228a6b5
This commit is contained in:
@@ -38,22 +38,20 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def get_pids():
|
def get_pids():
|
||||||
uwsgi_dict = {}
|
# needs to be compatible with psutil >= 1.1.1 since it's a global req.
|
||||||
|
PSUTIL2 = psutil.version_info >= (2, 0)
|
||||||
|
result = set([])
|
||||||
for pid in psutil.get_pid_list():
|
for pid in psutil.get_pid_list():
|
||||||
try:
|
try:
|
||||||
p = psutil.Process(pid)
|
p = psutil.Process(pid)
|
||||||
if p.cmdline and p.cmdline[0].find('/uwsgi'):
|
name = p.name() if PSUTIL2 else p.name
|
||||||
if p.parent:
|
if name == 'uwsgi':
|
||||||
uwsgi_dict[p.pid] = p.parent.pid
|
LOG.debug('Found uwsgi process, pid: %s', pid)
|
||||||
|
result.add(pid)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.debug('Exception while iterating process list: %s', e)
|
LOG.debug('Exception while iterating process list: %s', e)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
result = set()
|
|
||||||
for pid in uwsgi_dict:
|
|
||||||
if uwsgi_dict[pid] in uwsgi_dict:
|
|
||||||
result.add(pid)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ class MemcachedStorage(RuntimeStorage):
|
|||||||
stored_pids = self.memcached.get('pids') or set()
|
stored_pids = self.memcached.get('pids') or set()
|
||||||
for pid in stored_pids:
|
for pid in stored_pids:
|
||||||
if pid not in pids:
|
if pid not in pids:
|
||||||
|
LOG.debug('Purge dead uwsgi pid %s from pids list', pid)
|
||||||
self.memcached.delete('pid:%s' % pid)
|
self.memcached.delete('pid:%s' % pid)
|
||||||
|
|
||||||
self.memcached.set('pids', pids)
|
self.memcached.set('pids', pids)
|
||||||
@@ -175,11 +176,15 @@ class MemcachedStorage(RuntimeStorage):
|
|||||||
min_update = n
|
min_update = n
|
||||||
|
|
||||||
first_valid_update = self.memcached.get('first_valid_update') or 0
|
first_valid_update = self.memcached.get('first_valid_update') or 0
|
||||||
|
LOG.debug('Purge polled updates from %(first)s to %(min)s',
|
||||||
|
{'first': first_valid_update, 'min': min_update})
|
||||||
|
|
||||||
for delete_id_set in utils.make_range(first_valid_update, min_update,
|
for delete_id_set in utils.make_range(first_valid_update, min_update,
|
||||||
BULK_DELETE_SIZE):
|
BULK_DELETE_SIZE):
|
||||||
if not self.memcached.delete_multi(delete_id_set,
|
if not self.memcached.delete_multi(delete_id_set,
|
||||||
key_prefix=UPDATE_ID_PREFIX):
|
key_prefix=UPDATE_ID_PREFIX):
|
||||||
raise Exception('Failed to delete from memcache')
|
raise Exception('Failed to delete from memcache')
|
||||||
|
|
||||||
self.memcached.set('first_valid_update', min_update)
|
self.memcached.set('first_valid_update', min_update)
|
||||||
|
|
||||||
def _get_update_count(self):
|
def _get_update_count(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user