print a backtrace with debug() on each exception
This commit is contained in:
parent
c77acdbef4
commit
6edafa89a2
1 changed files with 17 additions and 11 deletions
|
|
@ -23,6 +23,7 @@ from __future__ import with_statement
|
||||||
from logging import debug
|
from logging import debug
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from threading import Thread, Event, RLock, Timer
|
from threading import Thread, Event, RLock, Timer
|
||||||
|
from .tools.misc import getBacktrace
|
||||||
|
|
||||||
__all__ = ['BackendsCall', 'CallErrors']
|
__all__ = ['BackendsCall', 'CallErrors']
|
||||||
|
|
||||||
|
|
@ -79,6 +80,18 @@ class BackendsCall(object):
|
||||||
debug('New timer for %s' % b)
|
debug('New timer for %s' % b)
|
||||||
self.threads.append(Timer(0, self._caller, (b, function, args, kwargs)).start())
|
self.threads.append(Timer(0, self._caller, (b, function, args, kwargs)).start())
|
||||||
|
|
||||||
|
|
||||||
|
def _store_error(self, b, e):
|
||||||
|
with self.mutex:
|
||||||
|
# TODO save backtrace and/or print it here (with debug)
|
||||||
|
self.errors.append((b, e))
|
||||||
|
debug(getBacktrace(e))
|
||||||
|
|
||||||
|
def _store_result(self, b, r):
|
||||||
|
with self.mutex:
|
||||||
|
self.responses.append((b,r))
|
||||||
|
self.response_event.set()
|
||||||
|
|
||||||
def _caller(self, b, function, args, kwargs):
|
def _caller(self, b, function, args, kwargs):
|
||||||
debug('Hello from timer %s' % b)
|
debug('Hello from timer %s' % b)
|
||||||
with b:
|
with b:
|
||||||
|
|
@ -90,9 +103,7 @@ class BackendsCall(object):
|
||||||
else:
|
else:
|
||||||
r = getattr(b, function)(*args, **kwargs)
|
r = getattr(b, function)(*args, **kwargs)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
with self.mutex:
|
self._store_error(b, e)
|
||||||
# TODO save backtrace and/or print it here (with debug)
|
|
||||||
self.errors.append((b, e))
|
|
||||||
else:
|
else:
|
||||||
debug('%s: Got answer! %s' % (b, r))
|
debug('%s: Got answer! %s' % (b, r))
|
||||||
|
|
||||||
|
|
@ -102,16 +113,11 @@ class BackendsCall(object):
|
||||||
for e in r:
|
for e in r:
|
||||||
# Lock mutex only in loop in case the iterator is slow
|
# Lock mutex only in loop in case the iterator is slow
|
||||||
# (for example if backend do some parsing operations)
|
# (for example if backend do some parsing operations)
|
||||||
with self.mutex:
|
self._store_result(b, e)
|
||||||
self.responses.append((b,e))
|
|
||||||
self.response_event.set()
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
with self.mutex:
|
self._store_error(b, e)
|
||||||
self.errors.append((b, e))
|
|
||||||
else:
|
else:
|
||||||
with self.mutex:
|
self._store_result(b, r)
|
||||||
self.responses.append((b,r))
|
|
||||||
self.response_event.set()
|
|
||||||
finally:
|
finally:
|
||||||
with self.mutex:
|
with self.mutex:
|
||||||
# This backend is now finished
|
# This backend is now finished
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue