Index: /trunk/src/VBox/ValidationKit/testdriver/reporter.py
===================================================================
--- /trunk/src/VBox/ValidationKit/testdriver/reporter.py	(revision 65814)
+++ /trunk/src/VBox/ValidationKit/testdriver/reporter.py	(revision 65815)
@@ -845,6 +845,8 @@
             self.xmlFlush();
             g_oLock.release();
-            self._doUploadFile(oSrcFile, sAltName, sDescription, sKind, 'text/plain');
-            g_oLock.acquire();
+            try:
+                self._doUploadFile(oSrcFile, sAltName, sDescription, sKind, 'text/plain');
+            finally:
+                g_oLock.acquire();
         elif sKind.startswith('screenshot/'):
             self.log(0, '*** Uploading "%s" - KIND: "%s" - DESC: "%s" ***'
@@ -852,6 +854,8 @@
             self.xmlFlush();
             g_oLock.release();
-            self._doUploadFile(oSrcFile, sAltName, sDescription, sKind, 'image/png');
-            g_oLock.acquire();
+            try:
+                self._doUploadFile(oSrcFile, sAltName, sDescription, sKind, 'image/png');
+            finally:
+                g_oLock.acquire();
         elif sKind.startswith('misc/'):
             self.log(0, '*** Uploading "%s" - KIND: "%s" - DESC: "%s" ***'
@@ -859,6 +863,8 @@
             self.xmlFlush();
             g_oLock.release();
-            self._doUploadFile(oSrcFile, sAltName, sDescription, sKind, 'application/octet-stream');
-            g_oLock.acquire();
+            try:
+                self._doUploadFile(oSrcFile, sAltName, sDescription, sKind, 'application/octet-stream');
+            finally:
+                g_oLock.acquire();
         else:
             self.log(0, '*** UNKNOWN FILE "%s" - KIND "%s" - DESC "%s" ***'
@@ -876,6 +882,8 @@
             self.xmlFlush();
             g_oLock.release();
-            self._doUploadString(sLog, sLogName, sDescription, sKind, 'text/plain');
-            g_oLock.acquire();
+            try:
+                self._doUploadString(sLog, sLogName, sDescription, sKind, 'text/plain');
+            finally:
+                g_oLock.acquire();
         else:
             self.log(0, '*** UNKNOWN FILE "%s" - KIND "%s" - DESC "%s" ***'
@@ -895,6 +903,8 @@
 
                 g_oLock.release();
-                (asXml, fIncErrors) = self._xmlDoFlush(asXml, fRetry = fRetry);
-                g_oLock.acquire();
+                try:
+                    (asXml, fIncErrors) = self._xmlDoFlush(asXml, fRetry = fRetry);
+                finally:
+                    g_oLock.acquire();
 
                 if fIncErrors:
@@ -954,9 +964,11 @@
         # this instead.
         g_oLock.acquire();
-        self._asXml += [ '<PushHint testdepth="%d"/>' % (len(self.atTests),),
-                         sRawXml,
-                         '<PopHint  testdepth="%d"/>' % (len(self.atTests),),];
-        self._xmlFlushIfNecessary();
-        g_oLock.release();
+        try:
+            self._asXml += [ '<PushHint testdepth="%d"/>' % (len(self.atTests),),
+                             sRawXml,
+                             '<PopHint  testdepth="%d"/>' % (len(self.atTests),),];
+            self._xmlFlushIfNecessary();
+        finally:
+            g_oLock.release();
         return None;
 
@@ -964,6 +976,8 @@
         if len(self._asXml) > 0:
             g_oLock.acquire();
-            self._xmlFlushIfNecessary(fPolling = True, sDebug = sDebug);
-            g_oLock.release();
+            try:
+                self._xmlFlushIfNecessary(fPolling = True, sDebug = sDebug);
+            finally:
+                g_oLock.release();
         return None;
 
@@ -979,55 +993,58 @@
     """
     g_oLock.acquire();
-    if fIncErrors:
-        g_oReporter.testIncErrors();
-
-    ## @todo skip all this if iLevel is too high!
-
-    # Try get exception info.
-    sTsPrf = utils.getTimePrefix();
-    try:
-        oType, oValue, oTraceback = sys.exc_info();
-    except:
-        oType = oValue = oTraceback = None;
-    if oType is not None:
-
-        # Try format the info
+    try:
+
+        if fIncErrors:
+            g_oReporter.testIncErrors();
+
+        ## @todo skip all this if iLevel is too high!
+
+        # Try get exception info.
+        sTsPrf = utils.getTimePrefix();
         try:
-            rc      = 0;
-            sCaller = utils.getCallerName(oTraceback.tb_frame);
-            if sText is not None:
-                rc = g_oReporter.log(iLevel, "%s%s" % (sPrefix, sText), sCaller, sTsPrf);
-            asInfo = [];
-            try:
-                asInfo = asInfo + traceback.format_exception_only(oType, oValue);
-                if cFrames is not None and cFrames <= 1:
-                    asInfo = asInfo + traceback.format_tb(oTraceback, 1);
+            oType, oValue, oTraceback = sys.exc_info();
+        except:
+            oType = oValue = oTraceback = None;
+        if oType is not None:
+
+            # Try format the info
+            try:
+                rc      = 0;
+                sCaller = utils.getCallerName(oTraceback.tb_frame);
+                if sText is not None:
+                    rc = g_oReporter.log(iLevel, "%s%s" % (sPrefix, sText), sCaller, sTsPrf);
+                asInfo = [];
+                try:
+                    asInfo = asInfo + traceback.format_exception_only(oType, oValue);
+                    if cFrames is not None and cFrames <= 1:
+                        asInfo = asInfo + traceback.format_tb(oTraceback, 1);
+                    else:
+                        asInfo.append('Traceback:')
+                        asInfo = asInfo + traceback.format_tb(oTraceback, cFrames);
+                        asInfo.append('Stack:')
+                        asInfo = asInfo + traceback.format_stack(oTraceback.tb_frame.f_back, cFrames);
+                except:
+                    g_oReporter.log(0, '** internal-error: Hit exception #2! %s' % (traceback.format_exc()), sCaller, sTsPrf);
+
+                if len(asInfo) > 0:
+                    # Do the logging.
+                    for sItem in asInfo:
+                        asLines = sItem.splitlines();
+                        for sLine in asLines:
+                            rc = g_oReporter.log(iLevel, '%s%s' % (sPrefix, sLine), sCaller, sTsPrf);
+
                 else:
-                    asInfo.append('Traceback:')
-                    asInfo = asInfo + traceback.format_tb(oTraceback, cFrames);
-                    asInfo.append('Stack:')
-                    asInfo = asInfo + traceback.format_stack(oTraceback.tb_frame.f_back, cFrames);
+                    g_oReporter.log(iLevel, 'No exception info...', sCaller, sTsPrf);
+                    rc = -3;
             except:
-                g_oReporter.log(0, '** internal-error: Hit exception #2! %s' % (traceback.format_exc()), sCaller, sTsPrf);
-
-            if len(asInfo) > 0:
-                # Do the logging.
-                for sItem in asInfo:
-                    asLines = sItem.splitlines();
-                    for sLine in asLines:
-                        rc = g_oReporter.log(iLevel, '%s%s' % (sPrefix, sLine), sCaller, sTsPrf);
-
-            else:
-                g_oReporter.log(iLevel, 'No exception info...', sCaller, sTsPrf);
-                rc = -3;
-        except:
-            g_oReporter.log(0, '** internal-error: Hit exception! %s' % (traceback.format_exc()), None, sTsPrf);
-            rc = -2;
-    else:
-        g_oReporter.log(0, '** internal-error: No exception! %s'
-                        % (utils.getCallerName(iFrame=3)), utils.getCallerName(iFrame=3), sTsPrf);
-        rc = -1;
-
-    g_oLock.release();
+                g_oReporter.log(0, '** internal-error: Hit exception! %s' % (traceback.format_exc()), None, sTsPrf);
+                rc = -2;
+        else:
+            g_oReporter.log(0, '** internal-error: No exception! %s'
+                            % (utils.getCallerName(iFrame=3)), utils.getCallerName(iFrame=3), sTsPrf);
+            rc = -1;
+
+    finally:
+        g_oLock.release();
     return rc;
 
@@ -1069,5 +1086,6 @@
         except:
             traceback.print_exc();
-        g_oLock.release();
+        finally:
+            g_oLock.release();
         return None;
 
@@ -1174,6 +1192,8 @@
             if sElement[1:idxEndName] == 'Failed':
                 g_oLock.acquire();
-                g_oReporter.testIncErrors();
-                g_oLock.release();
+                try:
+                    g_oReporter.testIncErrors();
+                finally:
+                    g_oLock.release();
         else:
             error('_processXmlElement(%s)' % sElement);
@@ -1191,5 +1211,6 @@
     except:
         rc = -1;
-    g_oLock.release();
+    finally:
+        g_oLock.release();
     return rc;
 
@@ -1208,5 +1229,6 @@
     except:
         rc = -1;
-    g_oLock.release();
+    finally:
+        g_oLock.release();
     return rc;
 
@@ -1252,10 +1274,11 @@
     """
     g_oLock.acquire();
-    g_oReporter.testIncErrors();
-    try:
+    try:
+        g_oReporter.testIncErrors();
         g_oReporter.log(0, '** error: %s' % (sText), utils.getCallerName(), utils.getTimePrefix());
     except:
         pass;
-    g_oLock.release();
+    finally:
+        g_oLock.release();
     return False;
 
@@ -1283,10 +1306,11 @@
     """
     g_oLock.acquire();
-    g_oReporter.testSetTimedOut();
-    try:
+    try:
+        g_oReporter.testSetTimedOut();
         g_oReporter.log(0, '** timeout-error: %s' % (sText), utils.getCallerName(), utils.getTimePrefix());
     except:
         pass;
-    g_oLock.release();
+    finally:
+        g_oLock.release();
     return False;
 
@@ -1301,10 +1325,11 @@
     """
     g_oLock.acquire();
-    g_oReporter.testIncErrors();
-    try:
+    try:
+        g_oReporter.testIncErrors();
         g_oReporter.log(0, '** fatal error: %s' % (sText), utils.getCallerName(), utils.getTimePrefix());
     except:
         pass
-    g_oLock.release();
+    finally:
+        g_oLock.release();
     return False;
 
@@ -1351,7 +1376,9 @@
     else:
         g_oLock.acquire();
-        fRc = g_oReporter.addLogFile(oSrcFile, sFilename, sAltName, sDescription, sKind, sCaller, sTsPrf);
-        g_oLock.release();
-        oSrcFile.close();
+        try:
+            fRc = g_oReporter.addLogFile(oSrcFile, sFilename, sAltName, sDescription, sKind, sCaller, sTsPrf);
+        finally:
+            g_oLock.release();
+            oSrcFile.close();
     return fRc;
 
@@ -1374,6 +1401,8 @@
 
     g_oLock.acquire();
-    fRc = g_oReporter.addLogString(sLog, sLogName, sDescription, sKind, sCaller, sTsPrf);
-    g_oLock.release();
+    try:
+        fRc = g_oReporter.addLogString(sLog, sLogName, sDescription, sKind, sCaller, sTsPrf);
+    finally:
+        g_oLock.release();
     return fRc;
 
@@ -1402,6 +1431,8 @@
     """
     g_oLock.acquire();
-    cErrors = g_oReporter.cErrors;
-    g_oLock.release();
+    try:
+        cErrors = g_oReporter.cErrors;
+    finally:
+        g_oLock.release();
     return cErrors;
 
@@ -1424,6 +1455,8 @@
     """
     g_oLock.acquire();
-    rc = g_oReporter.testStart(sName, utils.getCallerName());
-    g_oLock.release();
+    try:
+        rc = g_oReporter.testStart(sName, utils.getCallerName());
+    finally:
+        g_oLock.release();
     return rc;
 
@@ -1433,6 +1466,8 @@
     """
     g_oLock.acquire();
-    rc = g_oReporter.testValue(sName, str(sValue), sUnit, utils.getCallerName());
-    g_oLock.release();
+    try:
+        rc = g_oReporter.testValue(sName, str(sValue), sUnit, utils.getCallerName());
+    finally:
+        g_oLock.release();
     return rc;
 
@@ -1445,6 +1480,8 @@
     """
     g_oLock.acquire();
-    g_oReporter.testFailure(sDetails, utils.getCallerName());
-    g_oLock.release();
+    try:
+        g_oReporter.testFailure(sDetails, utils.getCallerName());
+    finally:
+        g_oLock.release();
     return False;
 
@@ -1470,9 +1507,11 @@
     # Use testFailure to do the work.
     g_oLock.acquire();
-    if sDetails == '':
-        g_oReporter.testFailure('Exception: %s' % (sXcpt,), sCaller);
-    else:
-        g_oReporter.testFailure('%s: %s' % (sDetails, sXcpt), sCaller);
-    g_oLock.release();
+    try:
+        if sDetails == '':
+            g_oReporter.testFailure('Exception: %s' % (sXcpt,), sCaller);
+        else:
+            g_oReporter.testFailure('%s: %s' % (sDetails, sXcpt), sCaller);
+    finally:
+        g_oLock.release();
     return False;
 
@@ -1484,6 +1523,8 @@
     """
     g_oLock.acquire();
-    rc = g_oReporter.testDone(fSkipped, utils.getCallerName());
-    g_oLock.release();
+    try:
+        rc = g_oReporter.testDone(fSkipped, utils.getCallerName());
+    finally:
+        g_oLock.release();
     return rc;
 
@@ -1495,6 +1536,8 @@
     """
     g_oLock.acquire();
-    cErrors = g_oReporter.testErrorCount();
-    g_oLock.release();
+    try:
+        cErrors = g_oReporter.testErrorCount();
+    finally:
+        g_oLock.release();
     return cErrors;
 
@@ -1506,7 +1549,9 @@
     """
     g_oLock.acquire();
-    fRc = g_oReporter.testCleanup(utils.getCallerName());
-    g_oReporter.xmlFlush(fRetry = False, fForce = True);
-    g_oLock.release();
+    try:
+        fRc = g_oReporter.testCleanup(utils.getCallerName());
+        g_oReporter.xmlFlush(fRetry = False, fForce = True);
+    finally:
+        g_oLock.release();
     return fRc;
 
@@ -1584,6 +1629,8 @@
     """
     g_oLock.acquire();
-    fRc = g_oReporter.xmlFlush(fRetry = False, fForce = True);
-    g_oLock.release();
+    try:
+        fRc = g_oReporter.xmlFlush(fRetry = False, fForce = True);
+    finally:
+        g_oLock.release();
     return fRc;
 
@@ -1600,6 +1647,8 @@
     if fSkipXml is not True:
         g_oLock.acquire();
-        g_oReporter.xmlFlush(fRetry = False);
-        g_oLock.release();
+        try:
+            g_oReporter.xmlFlush(fRetry = False);
+        finally:
+            g_oLock.release();
 
     return True;
