Commit fa0c8b64 authored by Robert's avatar Robert Committed by Robert Ohmacht

-logging of unsuccessful attempts of calling COM functions in WITecCOM (based on Josefs idea)

parent 900f1adb
......@@ -60,27 +60,35 @@ class WITecCOM(RamanBase):
"""
def wrapper(*args, **kwargs):
def tryFunctionThreeTimes():
def tryFunctionThreeTimes(c):
success = False
for _ in range(3):
result = None
c += 1
try:
result = comCallFunction(*args, **kwargs)
success = True
break
except pythoncom.com_error:
comObj.logger.warning(
f'Unsuccessful {c}. attempt for COM call of function {comCallFunction.__name__}\n{pythoncom.com_error}'
)
sleep(1.)
return success, result
return success, result, c
c = 0
comObj = args[0] #self is always passed as first argument
functionSucceeded, result = tryFunctionThreeTimes()
functionSucceeded, result, c = tryFunctionThreeTimes(c)
if not functionSucceeded:
comObj.logger.warning(f'Reconnecting for function {comCallFunction.__name__}')
comObj.disconnect()
sleep(1.)
comObj.connect()
functionSucceeded, result = tryFunctionThreeTimes()
functionSucceeded, result, c = tryFunctionThreeTimes(c)
if not functionSucceeded:
showErrorMessageAsWidget(f'Com error on function {comCallFunction.__name__}')
comObj.logger.warning(f'COM error: function {comCallFunction.__name__} could not be executed')
showErrorMessageAsWidget(f'COM error on function {comCallFunction.__name__}')
raise pythoncom.com_error
return result
return wrapper
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment