mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
lvmdbusd: Main thread exception logging
Make sure that any and all code that executes in the main thread is wrapped with a try/except block to ensure that at the very least we log when things are going wrong.
This commit is contained in:
parent
090db98828
commit
2074094e77
@ -8,7 +8,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from .automatedproperties import AutomatedProperties
|
from .automatedproperties import AutomatedProperties
|
||||||
from .utils import job_obj_path_generate, mt_async_result, mt_run_no_wait
|
from .utils import job_obj_path_generate, mt_async_call
|
||||||
from . import cfg
|
from . import cfg
|
||||||
from .cfg import JOB_INTERFACE
|
from .cfg import JOB_INTERFACE
|
||||||
import dbus
|
import dbus
|
||||||
@ -30,7 +30,7 @@ class WaitingClient(object):
|
|||||||
# Remove ourselves from waiting client
|
# Remove ourselves from waiting client
|
||||||
wc.job_state.remove_waiting_client(wc)
|
wc.job_state.remove_waiting_client(wc)
|
||||||
wc.timer_id = -1
|
wc.timer_id = -1
|
||||||
mt_async_result(wc.cb, wc.job_state.Complete)
|
mt_async_call(wc.cb, wc.job_state.Complete)
|
||||||
wc.job_state = None
|
wc.job_state = None
|
||||||
|
|
||||||
def __init__(self, job_state, tmo, cb, cbe):
|
def __init__(self, job_state, tmo, cb, cbe):
|
||||||
@ -55,7 +55,7 @@ class WaitingClient(object):
|
|||||||
GLib.source_remove(self.timer_id)
|
GLib.source_remove(self.timer_id)
|
||||||
self.timer_id = -1
|
self.timer_id = -1
|
||||||
|
|
||||||
mt_async_result(self.cb, self.job_state.Complete)
|
mt_async_call(self.cb, self.job_state.Complete)
|
||||||
self.job_state = None
|
self.job_state = None
|
||||||
|
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ class Job(AutomatedProperties):
|
|||||||
@Complete.setter
|
@Complete.setter
|
||||||
def Complete(self, value):
|
def Complete(self, value):
|
||||||
self.state.Complete = value
|
self.state.Complete = value
|
||||||
mt_run_no_wait(Job._signal_complete, self)
|
mt_async_call(Job._signal_complete, self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def GetError(self):
|
def GetError(self):
|
||||||
|
@ -13,7 +13,7 @@ from gi.repository import GLib
|
|||||||
from .job import Job
|
from .job import Job
|
||||||
from . import cfg
|
from . import cfg
|
||||||
import traceback
|
import traceback
|
||||||
from .utils import log_error, mt_async_result
|
from .utils import log_error, mt_async_call
|
||||||
|
|
||||||
|
|
||||||
class RequestEntry(object):
|
class RequestEntry(object):
|
||||||
@ -116,9 +116,9 @@ class RequestEntry(object):
|
|||||||
if error_rc == 0:
|
if error_rc == 0:
|
||||||
if self.cb:
|
if self.cb:
|
||||||
if self._return_tuple:
|
if self._return_tuple:
|
||||||
mt_async_result(self.cb, (result, '/'))
|
mt_async_call(self.cb, (result, '/'))
|
||||||
else:
|
else:
|
||||||
mt_async_result(self.cb, result)
|
mt_async_call(self.cb, result)
|
||||||
else:
|
else:
|
||||||
if self.cb_error:
|
if self.cb_error:
|
||||||
if not error_exception:
|
if not error_exception:
|
||||||
@ -129,7 +129,7 @@ class RequestEntry(object):
|
|||||||
else:
|
else:
|
||||||
error_exception = Exception(error_msg)
|
error_exception = Exception(error_msg)
|
||||||
|
|
||||||
mt_async_result(self.cb_error, error_exception)
|
mt_async_call(self.cb_error, error_exception)
|
||||||
else:
|
else:
|
||||||
# We have a job and it's complete, indicate that it's done.
|
# We have a job and it's complete, indicate that it's done.
|
||||||
self._job.Complete = True
|
self._job.Complete = True
|
||||||
|
@ -534,21 +534,27 @@ def add_no_notify(cmdline):
|
|||||||
# ensure all dbus library interaction is done from the same thread!
|
# ensure all dbus library interaction is done from the same thread!
|
||||||
|
|
||||||
|
|
||||||
def _async_result(call_back, results):
|
def _async_handler(call_back, parameters):
|
||||||
log_debug('Results = %s' % str(results))
|
params_str = ", ".join([str(x) for x in parameters])
|
||||||
call_back(results)
|
log_debug('Main thread execution, callback = %s, parameters = (%s)' %
|
||||||
|
(str(call_back), params_str))
|
||||||
|
|
||||||
|
try:
|
||||||
|
if parameters:
|
||||||
|
call_back(*parameters)
|
||||||
|
else:
|
||||||
|
call_back()
|
||||||
|
except:
|
||||||
|
st = traceback.format_exc()
|
||||||
|
log_error("mt_async_call: exception (logged, not reported!) \n %s" % st)
|
||||||
|
|
||||||
|
|
||||||
# Return result in main thread
|
# Execute the function on the main thread with the provided parameters, do
|
||||||
def mt_async_result(call_back, results):
|
# not return *any* value or wait for the execution to complete!
|
||||||
GLib.idle_add(_async_result, call_back, results)
|
def mt_async_call(function_call_back, *parameters):
|
||||||
|
GLib.idle_add(_async_handler, function_call_back, parameters)
|
||||||
|
|
||||||
|
|
||||||
# Take the supplied function and run it on the main thread and not wait for
|
|
||||||
# a result!
|
|
||||||
def mt_run_no_wait(function, param):
|
|
||||||
GLib.idle_add(function, param)
|
|
||||||
|
|
||||||
# Run the supplied function and arguments on the main thread and wait for them
|
# Run the supplied function and arguments on the main thread and wait for them
|
||||||
# to complete while allowing the ability to get the return value too.
|
# to complete while allowing the ability to get the return value too.
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user