def __evenlet_timeout_deco(*args, **kwargs): timeout = Timeout(timeout_t, ) # timeout.start() # 与gevent不一样,直接start了。 try: f(*args, **kwargs) except Timeout as t: logger_evenlet_timeout_deco.error( f'函数 {f} 运行超过了 {timeout_t} 秒') if t is not timeout: nb_print(t) # raise # not my timeout finally: timeout.cancel()
def read_with_timeout(self, size): timeout = Timeout(self.timeout) try: chunk = os.read(self.obj_data, size) except Timeout as t: if t is timeout: self.close() raise t except Exception as e: self.close() raise e finally: timeout.cancel() return chunk
def _train_r_model(self, cmd, model_name): print "MIXED: fitting ", cmd timeout = Timeout(2) try: model = r(cmd) rpy2.robjects.globalenv[model_name] = model params = self._extract_r_coefs(model_name) except: print "MIXED: timed out or broke. F**k you too R! filling model with 0's" print "MIXED: traceback:" print traceback.format_exc() model = None params = defaultdict(float) finally: timeout.cancel() return model, params
def read_with_timeout(self, size): timeout = Timeout(self.timeout) try: chunk = os.read(self.obj_data, size) except Timeout as t: if t is timeout: if self.cancel_func: self.cancel_func() self.close() raise t except Exception as e: self.close() raise e finally: timeout.cancel() return chunk
def _call(self, method_name, timeout_sec, **kwargs): LOG.debug("Calling %s" % method_name) timeout = Timeout(timeout_sec) try: result = rpc.call(self.context, self._get_routing_key(), {'method': method_name, 'args': kwargs}) LOG.debug("Result is %s" % result) return result except Exception as e: LOG.error(e) raise exception.GuestError(original_message=str(e)) except Timeout as t: if t is not timeout: raise else: raise exception.GuestTimeout() finally: timeout.cancel()
def _call(self, method_name, timeout_sec, **kwargs): LOG.debug("Calling %s" % method_name) timeout = Timeout(timeout_sec) try: result = rpc.call(self.context, self._get_routing_key(), { 'method': method_name, 'args': kwargs }) LOG.debug("Result is %s" % result) return result except Exception as e: LOG.error(e) raise exception.GuestError(original_message=str(e)) except Timeout as t: if t is not timeout: raise else: raise exception.GuestTimeout() finally: timeout.cancel()
def poll_response(self, response): """ The API might return a job nr in the response in case of a async response: https://github.com/fog/fog/issues/575 """ status = response.status timeout = Timeout(CONF[CFG_GROUP].job_timeout) try: while status == 307: time.sleep(1) url = response.headers.get('Location') LOG.debug("Polling %s" % url) polled_response = self.get(url) status = response.status except Timeout as t: if t == timeout: raise DynTimeoutError('Timeout reached when pulling job.') finally: timeout.cancel() return polled_response