def ssubmit(self, func_args_list, max_workers=4, continue_on_error=False): triplets = [] for func_args in func_args_list: res, exc, tb = self.saferun(func_args[0], *func_args[1:]) if exc and not continue_on_error: raise_(exc.__class__, exc, tb) triplets.append((res, exc, tb)) return triplets
def commit(self): etype, exc, tb = sys.exc_info() # the original error try: self.dbapi.commit() except: # for instance there is no connection to the server self.close() # close the dead connection # re-raise the original exception, not an useless cannot rollback raise_(etype, exc, tb)
def result(self, timeout=None): if self._got_result: raise RuntimeError('.result() can be called only once!') res, exc, tb = self._q.get(timeout=timeout) self._got_result = True if exc is not None: raise_(res, exc, tb) return res
def psubmit(self, func_args_list, max_workers=4, continue_on_error=False): with futures.ThreadPoolExecutor(max_workers) as tpe: futs = [tpe.submit(self.saferun, func_args[0], *func_args[1:]) for func_args in func_args_list] triplets = [] for future in futures.as_completed(futs): res, exc, tb = future.result() if exc and not continue_on_error: raise_(exc.__class__, exc, tb) triplets.append((res, exc, tb)) return triplets
def rollback(self): if self.autocommit: warnings.warn( 'Tried to rollback a transaction in autocommit mode', stacklevel=4) etype, exc, tb = sys.exc_info() # the original error try: self.dbapi.rollback() except: # for instance there is no connection to the server self.close() # close the dead connection # re-raise the original exception, not an useless cannot rollback raise_(etype, exc, tb)