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


Python Timeout.cancel方法代码示例

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


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

示例1: _get_message_data

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
    def _get_message_data(self):
        max_size = self.extensions.getparam('SIZE', filter=int)
        reader = DataReader(self.io, max_size)

        err = None
        timeout = Timeout(self.data_timeout)
        timeout.start()
        try:
            data = reader.recv()
        except ConnectionLost:
            raise
        except SmtpError as e:
            data = None
            err = e
        finally:
            timeout.cancel()

        reply = Reply('250', '2.6.0 Message Accepted for Delivery')
        self._call_custom_handler('HAVE_DATA', reply, data, err)

        self.io.send_reply(reply)
        self.io.flush_send()

        self.have_mailfrom = None
        self.have_rcptto = None
开发者ID:rafaelnovello,项目名称:python-slimta,代码行数:27,代码来源:server.py

示例2: __init__

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
    def __init__(self, url):
        self.url = url
        self.protocol, self.domain = self.url.split("://")  #e.g. news.bbc.co.uk
        self.domain = self.domain.split('/')[0]
        self.site_data = sites[self.domain]

        self.total_words = {}

        timeout = Timeout(30, TimeoutError)
        timeout.start()
        try:
            self.html = self.read_url()
        except TimeoutError:
            print url + " timed out"
            return 
        finally:
            timeout.cancel()

        self.text = self.boiler_extract()
        self.soup = BeautifulSoup(self.html, 'lxml')
        self.article = self.is_article()

        if self.article:
            self.calc_total_words()
            articles.put(self)

        self.find_links()
开发者ID:Timewire,项目名称:timewire,代码行数:29,代码来源:spider.py

示例3: main

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
def main(socket, address):
    global client_mgr
    print "one client", address
    logger.debug("one client %s" % str(address))
    client = Client(socket)
    hbTimer = None
    while True:
        try:
            hbTimer = Timeout(ONE_MOVE_MAX_TIME)
            hbTimer.start()
            client.read_and_deal_cmd()
            hbTimer.cancel()
        except Timeout, t:
            if t == hbTimer:
                print "client lose"
                client.lose_hb()
                client.cancel_timeout()
                if client.latitude != None:
                    client_mgr.remove_client(client)
                client = None
                break
            else:
                print "other timeout"
                hbTimer.cancel()
                client.deal_timeout()

        except:
开发者ID:talentsun,项目名称:soushang,代码行数:29,代码来源:server_main.py

示例4: _recv_command

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
 def _recv_command(self):
     timeout = Timeout(self.command_timeout)
     timeout.start()
     try:
         return self.io.recv_command()
     finally:
         timeout.cancel()
开发者ID:RoboticCheese,项目名称:python-slimta,代码行数:9,代码来源:server.py

示例5: func1

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
def func1():
    
        
    utc = arrow.utcnow()
    local = utc.to('Asia/Shanghai')
    ts = local.timestamp
    print arrow.get(ts)
    #print local.format('YYYY-MM-DD HH:mm:ss ZZ')
    
    """function and heartbeat"""
    
    ex = TimeoutException("timeout ex")
    
    #gevent timeout
    timeout = Timeout(6, ex)
    #start
    timeout.start()
    try:
        
        # exception will be raised here, after *seconds* 
        # passed since start() call
        
        gevent.sleep(3 * random.randint(1,4))
        #print "f1 heart beat"
        heartbeat("f1")

    except TimeoutException as ex:
        print ex
    finally:
        #cancel timeout
        timeout.cancel()
开发者ID:mabotech,项目名称:mabo_sup,代码行数:33,代码来源:heartbeat.py

示例6: initial_test

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
 def initial_test(self, address):
     try:
         timeout = Timeout(self.TIMEOUT, TestTimeout('The server timed out on the first command.'))
         timeout.start()
         TestClient(address).put('key', 'value')
     finally:
         timeout.cancel()
开发者ID:marilyne,项目名称:eece411-kvclient,代码行数:9,代码来源:base.py

示例7: _methodExecute

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
    def _methodExecute(self, method_, id_="", timeout_=0, **args):  # added the _ to make sure we have no conflicts with the code we execute
        timeoutObj = Timeout(timeout_)
        timeoutObj.start()

        if "lock_" in args:
            lock = args["lock_"]
            if lock != None:
                while not lock.checkCanExecute(id_):
                    # print "sleep for lock:%s for methodid:%s"% (lock,id_)
                    gevent.sleep(0.05)
            args.pop("lock_")

        try:
            result = method_(**args)
        except Exception as e:
            timeoutObj.cancel()
            self.methodError(id_, e)
            return None
        except Timeout as t:
            if t is not timeoutObj:
                raise RuntimeError("not my timeout")
            self.methodTimeout(id_)
            return None
        timeoutObj.cancel()
        if id_ in self.locksActive:
            self.locksActive.pop(id_)
            if lock != None:
                if id_ in lock.greenletsActive:
                    lock.greenletsActive.pop(id_)  # unlock the lock for this greenlet
            else:
                print "Could not find lock for id %s" % id_

        return result
开发者ID:jumpscale7,项目名称:jumpscale_prototypes,代码行数:35,代码来源:JobManager.py

示例8: reposts_crawler

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
def reposts_crawler():
    '''
    greenlet reposts crawler
    '''
    while not reposts_fetch_queue.empty():
        IS_NEED_REFETCH = False #when timeout or errors occur,put the url back into the task queue and the make sure the task is not set to done!
        try:
            wait_time = Timeout(MAX_WAIT_TIME)
            wait_time.start()
            url = reposts_fetch_queue.get()
            gevent.sleep(0.0)
            reposts_time = _http_call(url)
            for status in reposts_time['reposts']:
                if not status.get('deleted'):
                    weibo_created_at = datetime.strptime(status.get('created_at'), '%a %b %d %H:%M:%S +0800 %Y')
                    user_created_at = datetime.strptime(status.get('user').get('created_at'),
                                                        '%a %b %d %H:%M:%S +0800 %Y')
                    reposts_status_id = -1

                    if status.get('retweeted_status') is not None:
                        reposts_status = status['retweeted_status']
                        reposts_status_id = reposts_status['id']

                    weibo_params = (
                        status['id'], status['user']['id'], status['text'], status['source'], weibo_created_at,
                        reposts_status_id)
                    user_params = (
                        status['user']['id'], status['user']['screen_name'], status['user']['name'],
                        status['user']['province'],
                        status['user']['city'], status['user']['location'], status['user']['description'],
                        status['user']['profile_image_url'], status['user']['domain'], status['user']['gender'],
                        status['user']['followers_count'], status['user']['friends_count'],
                        status['user']['statuses_count']
                        ,
                        status['user']['favourites_count'], user_created_at, status['user']['verified'],
                        status['user']['verified_type'], status['user']['verified_reason'],
                        status['user']['bi_followers_count'] )
                    cursor.execute(REPOSTS_WEIBO_INSERT_SQL, weibo_params)
                    cursor.execute(REPOSTS_USER_INSERT_SQL, user_params)
        except Timeout as t:
            if t is wait_time:
            #                print '处理超时,等待重新抓取!'
                #put timeout url back into the task queue
                IS_NEED_REFETCH = True
        except Exception as e:
            IS_NEED_REFETCH = True
            logger.error(traceback.format_exc())
        finally:
            wait_time.cancel()
            if IS_NEED_REFETCH is not True:
                reposts_fetch_queue.task_done()
            #                print url + ' 抓取完成 --- 转发'
            else:
                reposts_fetch_queue.put(url)
                print status
                print url + ' 抓取失败 --- 转发'
开发者ID:xiocode,项目名称:xio,代码行数:58,代码来源:weibo_crawler.py

示例9: serve_for_test

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
 def serve_for_test(self):
     timeout = Timeout(10)
     timeout.start()
     try:
         while self.is_connected():
             if len(self.re_schedule_events) == 10 and len(self.heartbeat_events) == 10:
                 break
             gevent.sleep(0.01)
     finally:
         timeout.cancel()
开发者ID:AndrewPashkin,项目名称:plivoframework,代码行数:12,代码来源:test_inboundsocket.py

示例10: timeout_wrapper

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
 def timeout_wrapper(*args, **kwargs):
     t = Timeout(seconds,
         TestTimeout('Timed out after %d seconds' % seconds)
     )
     t.start()
     try:
         ret = func(*args, **kwargs)
     finally:
         t.cancel()
     return ret
开发者ID:lordmauve,项目名称:nucleon.amqp,代码行数:12,代码来源:utils.py

示例11: requestGet

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
 def requestGet(self, url):
     wait = random.random() * (wait_time[1] - wait_time[0])
     sleep(wait)
     timeout = Timeout(request_timeout)
     timeout.start()
     try:
         req = requests.get(url=url, verify=True, headers=headers, proxies=proxies)
     except IncompleteRead:
         pass
         # todo:未知错误,暂还未查清
     timeout.cancel()
     return req
开发者ID:cyhhao,项目名称:CrawlerImage,代码行数:14,代码来源:main.py

示例12: query_documents_with_timeout

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
def query_documents_with_timeout(*args, **kwargs):
    timeout = Timeout(30)
    timeout.start()

    try:
        gevent.sleep(0.0001)
        return query_documents(*args, **kwargs)

    except:
        return [[], 0]

    finally:
        timeout.cancel()
开发者ID:crystal1017,项目名称:tobaccowatcher_web,代码行数:15,代码来源:utils.py

示例13: get_commits

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
def get_commits():
    print('Start - {0}'.format(datetime.datetime.now()))
    timeout = Timeout(10)
    timeout.start()
    try:
        job_stack = [gevent.spawn(download(url)) for url in urls]
        gevent.joinall(job_stack)
    except Timeout:
        pass
    finally:
        timeout.cancel()
    cntx = OrderedDict(sorted(result.items()))
    return render_template('start.html', cntx=cntx)
    print('End - {0}'.format(datetime.datetime.now()))
开发者ID:netpastor,项目名称:test-ac-flask-app,代码行数:16,代码来源:start.py

示例14: generate

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
	def generate():
		result = None
		while result is None:
			try:
				timeout = Timeout(25)
				timeout.start()
				result = json.dumps(client.get_events(
					queue_id=queue_id,
					last_event_id=last_event_id))
				logging.debug('got a response')
			except Timeout:
				pass
			finally:
				timeout.cancel()
			yield result or ' '
开发者ID:gwillen,项目名称:quebecois-zulip-proxy,代码行数:17,代码来源:proxy.py

示例15: handle

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import cancel [as 别名]
 def handle(self, body):
     t = int((self.timestamp + self.expiration) - time.time())
     worker = self.get_worker(self.routing_key)
     log.debug("Running {0} with timeout {1} sec.".format(self.w_name, t))
     timeout = Timeout(t, TimeoutError)
     timeout.start()
     try:
         res = worker(body)
         log.debug('Task finished.')
         return res
     except Exception as e:
         log.debug(traceback.format_exc())
         log.error('Task error: {0}'.format(unicode(e)))
         return e
     finally:
         timeout.cancel()
开发者ID:drozdovsky,项目名称:crew,代码行数:18,代码来源:listener.py


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