当前位置: 首页>>代码示例>>Python>>正文


Python Timeout.cancel方法代码示例

本文整理汇总了Python中eventlet.timeout.Timeout.cancel方法的典型用法代码示例。如果您正苦于以下问题:Python Timeout.cancel方法的具体用法?Python Timeout.cancel怎么用?Python Timeout.cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eventlet.timeout.Timeout的用法示例。


在下文中一共展示了Timeout.cancel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute_with_timeout

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
def execute_with_timeout(*args, **kwargs):
    time = kwargs.get('timeout', 30)

    def cb_timeout():
        msg = (_("Time out after waiting"
                 " %(time)s seconds when running proc: %(args)s"
                 " %(kwargs)s") % {'time': time, 'args': args,
                                   'kwargs': kwargs})
        LOG.error(msg)
        raise exception.ProcessExecutionError(msg)

    timeout = Timeout(time)
    try:
        return execute(*args, **kwargs)
    except Timeout as t:
        if t is not timeout:
            LOG.error("Timeout reached but not from our timeout. This is bad!")
            raise
        else:
            msg = (_("Time out after waiting "
                     "%(time)s seconds when running proc: %(args)s"
                     " %(kwargs)s") % {'time': time, 'args': args,
                                       'kwargs': kwargs})
            LOG.error(msg)
            raise exception.ProcessExecutionError(msg)
    finally:
        timeout.cancel()
开发者ID:NeCTAR-RC,项目名称:trove,代码行数:29,代码来源:utils.py

示例2: readRegister

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
 def readRegister(self, address, cache=False, timeout=2):
     """Return the value of register at [address] location
     if timeout is elapsed, NoneValue is returned
     """
     if not isinstance(address, int):
         raise TypeError("Address must be an integer")
     if int(address) < 0 or int(address) > 255:
         raise ValueError("Address is out of range [0, 255]")
     if address in self.regs.keys() and cache:
         if not self.regs[address] == None:
             return self.regs[address]
     self.regs[address] = None
     self.vscp.sendSimpleEvent(
         vscp_class=constant.VSCP_CLASS1_PROTOCOL,
         vscp_type=constant.VSCP_TYPE_PROTOCOL_READ_REGISTER,
         vscp_data=[self.id, address],
     )
     try:
         timer = Timeout(timeout, self.__timeout)
         while self.regs[address] == None:
             time.sleep(0.02)
         timer.cancel()
         return self.regs[address]
     except VSCPException:
         return None
开发者ID:nos86,项目名称:VSCP-Helper-for-Python,代码行数:27,代码来源:VSCPManager.py

示例3: rengine_side

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
    def rengine_side(self, appid, token, uri):
        """ Handle rengine (client) GET requests """
        if not self.rengine_authorization_ok(appid, token):
            LOGGER.info('Rengine content request authorization fails')
            abort(401, 'Authorization failed')

        evt = Event()
        request_id = str(uuid4())
        self.request_id_events[request_id] = evt

        headers = ["%s: %s" % (header, val) for (header, val) in request.headers.items()]
        packet = ScpPacket.make_sfkcontent(uri, request_id, headers)
        try:
            self._send(packet, appid)
        except Exception as e:
            abort(500, str(e))

        LOGGER.debug("uri %s expected" % uri)
        timeout = Timeout(TIMEOUT)
        try:
            resp = evt.wait()
        except Timeout:
            del self.request_id_events[request_id]
            abort(504, 'Gateway Timeout')
        finally:
            timeout.cancel()

        LOGGER.debug("uri %s got" % uri)
        
        return resp
开发者ID:patamushta,项目名称:scp,代码行数:32,代码来源:staticserver.py

示例4: writeRegister

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
 def writeRegister(self, address, value, timeout=2):
     """Return True if value is correctly written
     if timeout is elapsed, False is returned
     """
     if not isinstance(address, int):
         raise TypeError("Address must be an integer")
     if int(address) < 0 or int(address) > 255:
         raise ValueError("Address is out of range [0, 255]")
     if not isinstance(value, int):
         raise TypeError("Value must be an integer")
     if int(value) < 0 or int(value) > 255:
         raise ValueError("Value is out of range [0, 255]")
     self.regs[address] = None
     self.vscp.sendSimpleEvent(
         vscp_class=constant.VSCP_CLASS1_PROTOCOL,
         vscp_type=constant.VSCP_TYPE_PROTOCOL_WRITE_REGISTER,
         vscp_data=[self.id, address, value],
     )
     try:
         timer = Timeout(timeout, self.__timeout)
         self.regs[address] = None
         while self.regs[address] == None:
             time.sleep(0.02)
         timer.cancel()
         return self.regs[address] == value
     except VSCPException:
         return False
开发者ID:nos86,项目名称:VSCP-Helper-for-Python,代码行数:29,代码来源:VSCPManager.py

示例5: shrink_cluster

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
    def shrink_cluster(self, context, cluster_id, instance_ids):
        LOG.debug("begin shrink_cluster for MongoDB cluster %s" % cluster_id)

        def _shrink_cluster():
            def all_instances_marked_deleted():
                non_deleted_instances = DBInstance.find_all(
                    cluster_id=cluster_id, deleted=False).all()
                non_deleted_ids = [db_instance.id for db_instance
                                   in non_deleted_instances]
                return not bool(
                    set(instance_ids).intersection(set(non_deleted_ids))
                )
            try:
                utils.poll_until(all_instances_marked_deleted,
                                 sleep_time=2,
                                 time_out=CONF.cluster_delete_time_out)
            except PollTimeOut:
                LOG.error(_("timeout for instances to be marked as deleted."))
                return

        cluster_usage_timeout = CONF.cluster_usage_timeout
        timeout = Timeout(cluster_usage_timeout)
        try:
            _shrink_cluster()
            self.reset_task()
        except Timeout as t:
            if t is not timeout:
                raise  # not my timeout
            LOG.exception(_("timeout for shrinking cluster."))
            self.update_statuses_on_failure(cluster_id)
        finally:
            timeout.cancel()

        LOG.debug("end shrink_cluster for MongoDB cluster %s" % self.id)
开发者ID:Hopebaytech,项目名称:trove,代码行数:36,代码来源:taskmanager.py

示例6: grow_cluster

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
    def grow_cluster(self, context, cluster_id, new_instance_ids):

        def _grow_cluster():
            LOG.debug("begin grow_cluster for Vertica cluster %s" % cluster_id)

            db_instances = DBInstance.find_all(cluster_id=cluster_id,
                                               deleted=False).all()

            instance_ids = [db_instance.id for db_instance in db_instances]

            # Wait for new cluster members to get to cluster-ready status.
            if not self._all_instances_ready(new_instance_ids, cluster_id):
                return

            new_insts = [Instance.load(context, instance_id)
                         for instance_id in new_instance_ids]

            existing_instances = [Instance.load(context, instance_id)
                                  for instance_id
                                  in instance_ids
                                  if instance_id not in new_instance_ids]

            existing_guests = [self.get_guest(i) for i in existing_instances]
            new_guests = [self.get_guest(i) for i in new_insts]
            all_guests = new_guests + existing_guests

            authorized_users_without_password = ['root', 'dbadmin']
            new_ips = [self.get_ip(instance) for instance in new_insts]

            for user in authorized_users_without_password:
                pub_key = [guest.get_public_keys(user) for guest in all_guests]
                for guest in all_guests:
                    guest.authorize_public_keys(user, pub_key)

            for db_instance in db_instances:
                if db_instance['type'] == 'master':
                    LOG.debug("Found 'master' instance, calling grow on guest")
                    master_instance = Instance.load(context,
                                                    db_instance.id)
                    self.get_guest(master_instance).grow_cluster(new_ips)
                    break

            for guest in new_guests:
                guest.cluster_complete()

        timeout = Timeout(CONF.cluster_usage_timeout)

        try:
            _grow_cluster()
            self.reset_task()
        except Timeout as t:
            if t is not timeout:
                raise  # not my timeout
            LOG.exception(_("Timeout for growing cluster."))
            self.update_statuses_on_failure(cluster_id)
        except Exception:
            LOG.exception(_("Error growing cluster %s.") % cluster_id)
            self.update_statuses_on_failure(cluster_id)
        finally:
            timeout.cancel()
开发者ID:Hopebaytech,项目名称:trove,代码行数:62,代码来源:taskmanager.py

示例7: piper

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
    def piper(self, in_sock, out_sock, out_addr, onkill):
        "Worker thread for data reading"
        try:
            timeout = Timeout(self.transmission_timeout_seconds)
            try:
                while True:
                    written = in_sock.recv(32768)
                    if not written:
                        try:
                            out_sock.shutdown(socket.SHUT_WR)
                        except socket.error:
                            self.threads[onkill].kill()
                        break
                    try:
                        out_sock.sendall(written)
                    except socket.error:
                        pass
                    self.data_handled += len(written)
            finally:
                timeout.cancel()
        except greenlet.GreenletExit:
            return
        except Timeout:
            # This one prevents only from closing connection without any data nor status code returned
            # from mantrid when no data was received from backend.
            # When it happens, nginx reports 'upstream prematurely closed connection' and returns 500,
            # and want to have our custom error page to know when it happens. 

            if onkill == "stoc" and self.data_handled == 0:
                out_sock.sendall("HTTP/1.0 594 Backend timeout\r\nConnection: close\r\nContent-length: 0\r\n\r\n")
            logging.warn("Timeout serving request to backend %s of %s", self.backend, self.host)
            return
开发者ID:futuresimple,项目名称:mantrid,代码行数:34,代码来源:socketmeld.py

示例8: execute_with_timeout

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
def execute_with_timeout(*args, **kwargs):
    time = kwargs.pop('timeout', 30)
    log_output_on_error = kwargs.pop('log_output_on_error', False)

    timeout = Timeout(time)
    try:
        return execute(*args, **kwargs)
    except exception.ProcessExecutionError as e:
        if log_output_on_error:
            LOG.error(
                _("Command '%(cmd)s' failed. %(description)s "
                  "Exit code: %(exit_code)s\nstderr: %(stderr)s\n"
                  "stdout: %(stdout)s") %
                {'cmd': e.cmd, 'description': e.description or '',
                 'exit_code': e.exit_code, 'stderr': e.stderr,
                 'stdout': e.stdout})
        raise
    except Timeout as t:
        if t is not timeout:
            LOG.error(_("Got a timeout but not the one expected."))
            raise
        else:
            msg = (_("Time out after waiting "
                     "%(time)s seconds when running proc: %(args)s"
                     " %(kwargs)s.") % {'time': time, 'args': args,
                                        'kwargs': kwargs})
            LOG.error(msg)
            raise exception.ProcessExecutionError(msg)
    finally:
        timeout.cancel()
开发者ID:jiangytcn,项目名称:transformer,代码行数:32,代码来源:utils.py

示例9: create_cluster

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
    def create_cluster(self, context, cluster_id):
        LOG.debug("Begin create_cluster for id: %s." % cluster_id)

        def _create_cluster():

            # Fetch instances by cluster_id against instances table.
            db_instances = DBInstance.find_all(cluster_id=cluster_id).all()
            instance_ids = [db_instance.id for db_instance in db_instances]

            # Wait for cluster members to get to cluster-ready status.
            if not self._all_instances_ready(instance_ids, cluster_id):
                return

            LOG.debug("All members ready, proceeding for cluster setup.")
            instances = [Instance.load(context, instance_id) for instance_id
                         in instance_ids]

            # Connect nodes to the first node
            guests = [self.get_guest(instance) for instance in instances]
            try:
                cluster_head = instances[0]
                cluster_head_port = '6379'
                cluster_head_ip = self.get_ip(cluster_head)
                for guest in guests[1:]:
                    guest.cluster_meet(cluster_head_ip, cluster_head_port)

                num_nodes = len(instances)
                total_slots = 16384
                slots_per_node = total_slots / num_nodes
                leftover_slots = total_slots % num_nodes
                first_slot = 0
                for guest in guests:
                    last_slot = first_slot + slots_per_node
                    if leftover_slots > 0:
                        leftover_slots -= 1
                    else:
                        last_slot -= 1
                    guest.cluster_addslots(first_slot, last_slot)
                    first_slot = last_slot + 1

                for guest in guests:
                    guest.cluster_complete()
            except Exception:
                LOG.exception(_("Error creating cluster."))
                self.update_statuses_on_failure(cluster_id)

        timeout = Timeout(CONF.cluster_usage_timeout)
        try:
            _create_cluster()
            self.reset_task()
        except Timeout as t:
            if t is not timeout:
                raise  # not my timeout
            LOG.exception(_("Timeout for building cluster."))
            self.update_statuses_on_failure(cluster_id)
        finally:
            timeout.cancel()

        LOG.debug("End create_cluster for id: %s." % cluster_id)
开发者ID:Hopebaytech,项目名称:trove,代码行数:61,代码来源:taskmanager.py

示例10: request

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
 def request(self, address, path, method='GET', params=None, headers={}):
     t = Timeout(2, RuntimeError("Timeout trying to send request."))
     try:
         conn = httplib.HTTPConnection("%s:%s" % address)
         conn.request(method, path, params, headers)
     finally:
         t.cancel()
     return conn.getresponse()
开发者ID:DeadWisdom,项目名称:Minister,代码行数:10,代码来源:test_service.py

示例11: create_cluster

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
    def create_cluster(self, context, cluster_id):
        LOG.debug("Begin create_cluster for id: %s." % cluster_id)

        def _create_cluster():

            # Fetch instances by cluster_id against instances table.
            db_instances = DBInstance.find_all(cluster_id=cluster_id).all()
            instance_ids = [db_instance.id for db_instance in db_instances]

            # Wait for cluster members to get to cluster-ready status.
            if not self._all_instances_ready(instance_ids, cluster_id):
                return

            LOG.debug("All members ready, proceeding for cluster setup.")
            instances = [Instance.load(context, instance_id) for instance_id
                         in instance_ids]

            member_ips = [self.get_ip(instance) for instance in instances]
            guests = [self.get_guest(instance) for instance in instances]

            # Users to be configured for password-less SSH.
            authorized_users_without_password = ['root', 'dbadmin']

            # Configuring password-less SSH for cluster members.
            # Strategy for setting up SSH:
            # get public keys for user from member-instances in cluster,
            # combine them, finally push it back to all instances,
            # and member instances add them to authorized keys.
            LOG.debug("Configuring password-less SSH on cluster members.")
            try:
                for user in authorized_users_without_password:
                    pub_key = [guest.get_public_keys(user) for guest in guests]
                    for guest in guests:
                        guest.authorize_public_keys(user, pub_key)

                LOG.debug("Installing cluster with members: %s." % member_ips)
                guests[0].install_cluster(member_ips)

                LOG.debug("Finalizing cluster configuration.")
                for guest in guests:
                    guest.cluster_complete()
            except Exception:
                LOG.exception(_("Error creating cluster."))
                self.update_statuses_on_failure(cluster_id)

        timeout = Timeout(CONF.cluster_usage_timeout)
        try:
            _create_cluster()
            self.reset_task()
        except Timeout as t:
            if t is not timeout:
                raise  # not my timeout
            LOG.exception(_("Timeout for building cluster."))
            self.update_statuses_on_failure(cluster_id)
        finally:
            timeout.cancel()

        LOG.debug("End create_cluster for id: %s." % cluster_id)
开发者ID:cp16net,项目名称:trove,代码行数:60,代码来源:taskmanager.py

示例12: wrapper

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
 def wrapper(*args,**kwargs):
     timeout = Timeout(time, exception)
     try:
         func(*args,**kwargs)
     except exception as e:
         if reraise:
             raise e
     else:
         timeout.cancel()
开发者ID:patamushta,项目名称:scp,代码行数:11,代码来源:common.py

示例13: update_data

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
 def update_data(self):
     print "updating data"
     timeout = Timeout(10)
     try:
         self.parser = KMLParser()
         temp = self.parse_data()
         timeout.cancel()
         self.bikeways = temp
         self.update_database()
     except:
         print "couldn't get data"
开发者ID:cs310-2015ST1,项目名称:TeamShenolivin,代码行数:13,代码来源:models.py

示例14: _write_with_timeout

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
 def _write_with_timeout(self, writer, chunk):
     timeout = Timeout(self.timeout)
     try:
         writer.write(chunk)
     except Timeout as t:
         if t is timeout:
             writer.close()
             raise t
     except Exception as e:
         raise e
     finally:
         timeout.cancel()
开发者ID:ymoatti,项目名称:swift-storlets,代码行数:14,代码来源:storlet_runtime.py

示例15: add_shard_cluster

# 需要导入模块: from eventlet.timeout import Timeout [as 别名]
# 或者: from eventlet.timeout.Timeout import cancel [as 别名]
    def add_shard_cluster(self, context, cluster_id, shard_id,
                          replica_set_name):

        LOG.debug("begin add_shard_cluster for cluster %s shard %s"
                  % (cluster_id, shard_id))

        def _add_shard_cluster():

            db_instances = DBInstance.find_all(cluster_id=cluster_id,
                                               shard_id=shard_id).all()
            instance_ids = [db_instance.id for db_instance in db_instances]
            LOG.debug("instances in shard %s: %s" % (shard_id,
                                                     instance_ids))
            if not self._all_instances_ready(instance_ids, cluster_id,
                                             shard_id):
                return

            members = [Instance.load(context, instance_id)
                       for instance_id in instance_ids]

            if not self._create_replica_set(members, cluster_id, shard_id):
                return

            db_query_routers = DBInstance.find_all(cluster_id=cluster_id,
                                                   type='query_router',
                                                   deleted=False).all()
            query_routers = [Instance.load(context, db_query_router.id)
                             for db_query_router in db_query_routers]

            if not self._create_shard(query_routers, replica_set_name,
                                      members, cluster_id, shard_id):
                return

            for member in members:
                self.get_guest(member).cluster_complete()

        cluster_usage_timeout = CONF.cluster_usage_timeout
        timeout = Timeout(cluster_usage_timeout)
        try:
            _add_shard_cluster()
            self.reset_task()
        except Timeout as t:
            if t is not timeout:
                raise  # not my timeout
            LOG.exception(_("timeout for building shard."))
            self.update_statuses_on_failure(cluster_id, shard_id)
        finally:
            timeout.cancel()

        LOG.debug("end add_shard_cluster for cluster %s shard %s"
                  % (cluster_id, shard_id))
开发者ID:ShaguftaMethwani,项目名称:trove,代码行数:53,代码来源:taskmanager.py


注:本文中的eventlet.timeout.Timeout.cancel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。