Beispiel #1
0
def untilConcludes(is_active_cb, f, *a, **kw):
    wait = 0
    while is_active_cb():
        try:
            return f(*a, **kw)
        except socket.timeout as e:
            log("untilConcludes(%s, %s, %s, %s) %s", is_active_cb, f, a, kw, e)
            continue
        except TypeError:
            log.warn("untilConcludes error calling %s with %s", f, a)
            raise
        except (IOError, OSError) as e:
            code = e.args[0]
            can_continue = CONTINUE.get(code)
            if can_continue:
                log("untilConcludes(%s, %s, %s, %s) %s / %s (continue)",
                    is_active_cb, f, a, kw, can_continue, e)
                time.sleep(
                    wait /
                    1000.0)  #wait is in milliseconds, sleep takes seconds
                if wait < continue_wait:
                    wait += 1
                continue
            abort = ABORT.get(code, code)
            if abort is not None:
                raise ConnectionClosedException(e)
            log("untilConcludes(%s, %s, %s, %s) %s / %s (raised)",
                is_active_cb, f, a, kw, abort, e)
            raise
Beispiel #2
0
def can_retry(e):
    continue_exception = CONTINUE_EXCEPTIONS.get(type(e))
    if continue_exception:
        return continue_exception
    if isinstance(e, (IOError, OSError)):
        global CONTINUE
        code = e.args[0]
        can_continue = CONTINUE.get(code)
        if can_continue:
            return can_continue

        abort = ABORT.get(code, code)
        if abort is not None:
            log("untilConcludes: %s, args=%s, code=%s, abort=%s", type(e),
                e.args, code, abort)
            raise ConnectionClosedException(e)
    return False
Beispiel #3
0
 def abort_test(self, action):
     p = self.process
     if p is None or p.poll():
         raise ConnectionClosedException(
             "cannot %s: subprocess has terminated" % action)