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


Python Timeout.start方法代码示例

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


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

示例1: make_conn

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [as 别名]
def make_conn(url,timelimit):
    global SUCCESS_RECORD,FAIL_RECORD,TOTAL_SIZE,REQTIME_ARR
    time_start = time.time()
    
    if timelimit:
        timeout = Timeout(timelimit)
        timeout.start()
    
    try:
        f = urlopen(url)
        if f.getcode() == 200:
            time_end = time.time()
            server_info = f.info()
            content_type = server_info['content-type'].split(";")[0]
            if content_type == "text/html":
                data = f.read()
		size = int(server_info['content-length'])
            else:
                size = int(server_info['content-length'])
            REQTIME_ARR.append((time_end - time_start) * 1000)
            TOTAL_SIZE = TOTAL_SIZE + size
            SUCCESS_RECORD += 1
        else:
            FAIL_RECORD += 1
    except Timeout:
        FAIL_RECORD += 1
        return
    except Exception,e:
        FAIL_RECORD += 1
        return
开发者ID:code-breaker,项目名称:python-benchmark,代码行数:32,代码来源:benchmark.py

示例2: __init__

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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: initial_test

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例4: _get_message_data

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例5: _recv_command

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例6: main

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例7: execute

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [as 别名]
    def execute(self, name, args, func_type='PY'):        

        module_path = settings['MODULE_PATH'] #"c:/mtp/mabotech/maboss1.1"
        
        info = "[%s]%s:%s" % (module_path, func_type, name)
        log.debug( info)
        
        t = time.time()
        
        if name == "time":
            #for reconnection testing
            return t
        
        #Sync Code Here !!!
        
        timeout = Timeout(5, Exception)
        timeout.start()
        try:
            #...  # exception will be raised here, after *seconds* passed since start() call
            rtn = "OK"
            rtn = py_executor.execute(name, args, module_path) 
            #gevent.sleep(0.02)
            pf_log.debug("%10.5f,%s,%s" %(time.time()-t, func_type, name ) )
            
            return rtn                    
        except Exception, e:
            log.error(e.message)
开发者ID:mabotech,项目名称:maboss.py,代码行数:29,代码来源:job_server.py

示例8: sample

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [as 别名]
def sample():
    timeout = Timeout(5)
    timeout.start()
    try:
        gevent.spawn(wait).join()
    except Timeout:
        print 'Could not complete'
开发者ID:vhnuuh,项目名称:pyutil,代码行数:9,代码来源:timeout.py

示例9: func1

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例10: _methodExecute

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例11: read_url

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [as 别名]
def read_url(url):
    timeout = Timeout(10)
    timeout.start()
    try:
        response = urllib2.urlopen(url)
        reason, other = response.getcode(), response.msg
    except Timeout, t:
        reason, other = 'gevent timeout', 0
开发者ID:myhat123,项目名称:rdgunicorn,代码行数:10,代码来源:test.py

示例12: run_cmd

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [as 别名]
def run_cmd(args, timeout=None):
    _init()
    args = list(args)
    for i, x in enumerate(args):
        if isinstance(x, unicode):
            args[i] = x.encode("utf-8")

    sp = socket.socketpair()
    pid = os.fork()
    if pid == 0:
        # client
        try:
            os.dup2(sp[1].fileno(), 1)
            os.dup2(sp[1].fileno(), 2)
            sp[0].close()
            sp[1].close()
            os.execvp(args[0], args)
        except:
            stderr = os.fdopen(2, "w", 0)
            os.write(2, "failed to exec child process: %r\nPATH=%r" % (args, os.environ.get('PATH')))
            traceback.print_exc(file=stderr)
        finally:
            os._exit(97)

    pid2status[pid] = event.AsyncResult()
    if not _nochild:

        def cb():
            pid2status[pid].set(child_watcher.rstatus)
            child_watcher.stop()

        child_watcher = get_hub().loop.child(pid)
        child_watcher.start(cb)

    sp[1].close()

    chunks = []

    # prevent loopexit. see test_run_cmd_trigger_loopexit in test_proc.py
    if timeout is None:
        timeout = 2 ** 30

    timeout = Timeout(timeout)
    timeout.start()
    try:
        while 1:
            chunk = sp[0].recv(4096)
            if not chunk:
                break
            chunks.append(chunk)

        st = pid2status[pid].get()
        del pid2status[pid]

        return st, "".join(chunks)
    except Timeout, t:
        if t is not timeout:
            raise
开发者ID:pediapress,项目名称:qserve,代码行数:60,代码来源:proc.py

示例13: reposts_crawler

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例14: serve_for_test

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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

示例15: timeout_wrapper

# 需要导入模块: from gevent import Timeout [as 别名]
# 或者: from gevent.Timeout import start [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


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