'Called to terminate the application.'

def terminate(self, exitstatus=0, errortitle=None, errormsg=None):

    if (not self.exc_queue.empty()):
        self.warn('ERROR:    Exceptions    occurred    during    the    run!')
        if (exitstatus == 0):
            exitstatus = 1
    while (not self.exc_queue.empty()):
        (msg, exc, exc_traceback) = self.exc_queue.get()
        if msg:
            self.warn(('ERROR:    %s\n        %s' % (msg, exc)))
        else:
            self.warn(('ERROR:    %s' % exc))
        if exc_traceback:
            self.warn(('\nTraceback:\n%s' % ''.join(traceback.format_tb(exc_traceback))))
    if (errormsg and errortitle):
        self.warn(('ERROR:    %s\n\n%s\n' % (errortitle, errormsg)))
    elif errormsg:
        self.warn(('%s\n' % errormsg))
    if self.uidval_problem:
        self.warn('At    least    one    folder    skipped    due    to    UID    validity    problem')
        if (exitstatus == 0):
            exitstatus = 2
    sys.exit(exitstatus)
