• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python time._sleep函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中time._sleep函数的典型用法代码示例。如果您正苦于以下问题:Python _sleep函数的具体用法?Python _sleep怎么用?Python _sleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: wd_test

def wd_test(log):
    ws = WorkDispatcher(tmin=5, tmax=10, log=log)
    i = 0
    total = 0
    works = []
    try:
        ws.serve()
        while True:
            wk = WorkTest(name='work_%05d' % i)
            # wk.cancel()
            ws.addWork(wk)
            works.append(wk)
            if i > 50:
                ws.mgr.pauseAll()
            if i > 100:
                ws.mgr.resumeAll()
            i += 1
            total += 1
            log.error('workers = %d', ws.mgr.count())
            if i > 200:
                break
            if i < 190:
                _sleep(0.3)
    except Exception as e:
        log.exception(e)
        raise
    finally:
        # _sleep(1)
        ws.setToStop()
        ws.joinAll()
        for wk in works:
            log.error('[%s] status=%d', wk.name, wk.status)
        log.error('total=%d, count=%d', total, WorkTest.TOTAL)
开发者ID:pkhopper,项目名称:vavava,代码行数:33,代码来源:threadutil.py


示例2: run

    def run(self):
        self.log.debug('[ws] start serving')
        self.__wd.serve()
        self.__clean.serve()
        self._set_server_available()
        # monitor = _Moniter(self.log)
        while not self.isSetStop():
            # monitor.report(self.info())
            curr_task = None
            start_at = _time()
            try:
                if not self.__task_buff.empty():
                    curr_task = self.__task_buff.get()
                    self.__curr_tasks.append(curr_task)
                    curr_task._call_by_ws_set_status(ST_WORKING)
                    self.__wd.addWorks(curr_task.subWorks)
                    self.log.debug('[ws] pop a Task: %s', curr_task.name)
                    curr_task = None

                for i, tk in enumerate(self.__curr_tasks):
                    wkarchvied = True
                    for wk in tk.subWorks:
                        if wk.status != ST_FINISHED:
                            wkarchvied = False
                        elif wk.status == ST_ERROR:
                            tk._call_by_ws_set_status(ST_ERROR)
                            tk.setToStop()
                            tk.waitForStop()
                            self.log.debug('[ws] Task err: %s', tk.name)
                            del self.__curr_tasks[i]
                        elif wk.status == ST_CANCEL:
                            tk._call_by_ws_set_status(ST_CANCEL)
                            tk.setToStop()
                            tk.waitForStop()
                            self.log.debug('[ws] Task canceled: %s', tk.name)
                            del self.__curr_tasks[i]
                    if wkarchvied:
                        tk._call_by_ws_set_status(ST_FINISHED)
                        self.log.debug('[ws] Task done: %s', tk.name)
                        del self.__curr_tasks[i]
                    if tk.status > ST_WORKING:
                        self.log.debug('[ws] cleanup')
                        self.__clean.addWork(WorkShop.SerWork(tk))
            except Exception as e:
                # TODO: fetal err, need handle and report
                if curr_task:
                    curr_task._call_by_ws_set_status(ST_ERROR)
                self.log.exception(e)
            finally:
                duration = _time() - start_at
                if duration < 0.8:
                    _sleep(0.5)

        self._set_server_available(flag=False)
        self.__wd.setToStop()
        self.__wd.joinAll()
        self.__cleanUp()
        self.__clean.setToStop()
        self.__clean.joinAll()
        self.log.debug('[ws] stop serving')
开发者ID:pkhopper,项目名称:vavava,代码行数:60,代码来源:threadutil.py


示例3: put

    def put(self, item, block=True, timeout=None): 
        """Put item into the queue"""

        if self.maxsize > 0:
            if not block:
                if self.qsize() >= self.maxsize:
                    raise Full('Redis queue is full')
            elif timeout is None:
                while self.qsize() >= self.maxsize:
                    _sleep(0.1)
            elif timeout < 0:
                raise ValueError("'timeout' must be a positive number")
            else:
                endtime = _time() + timeout
                while self.qsize() >= self.maxsize:
                    remaining = endtime - _time()
                    if remaining <= 0.0:
                        raise Full('Redis queue is full')
                    _sleep(0.1)
        
        if type(item) is not list:
            item = [item, ]
        elif len(item)<1:
            return False
            
        pipe = self.__db.pipeline()   
        for i in item:
            i = self.__serialize(i)
            pipe.lpush(self.key, i)    
        pipe.execute()      
开发者ID:ivansurov,项目名称:django-async-tasks,代码行数:30,代码来源:redisqueue.py


示例4: DeadlockWrap

def DeadlockWrap(function, *_args, **_kwargs):
    """DeadlockWrap(function, *_args, **_kwargs) - automatically retries
    function in case of a database deadlock.

    This is a function intended to be used to wrap database calls such
    that they perform retrys with exponentially backing off sleeps in
    between when a DBLockDeadlockError exception is raised.

    A 'max_retries' parameter may optionally be passed to prevent it
    from retrying forever (in which case the exception will be reraised).

        d = DB(...)
        d.open(...)
        DeadlockWrap(d.put, "foo", data="bar")  # set key "foo" to "bar"
    """
    sleeptime = _deadlock_MinSleepTime
    max_retries = _kwargs.get("max_retries", -1)
    if _kwargs.has_key("max_retries"):
        del _kwargs["max_retries"]
    while 1:
        try:
            return function(*_args, **_kwargs)
        except db.DBLockDeadlockError:
            if _deadlock_VerboseFile:
                _deadlock_VerboseFile.write("dbutils.DeadlockWrap: sleeping %1.3f\n" % sleeptime)
            _sleep(sleeptime)
            # exponential backoff in the sleep time
            sleeptime *= 2
            if sleeptime > _deadlock_MaxSleepTime:
                sleeptime = _deadlock_MaxSleepTime
            max_retries -= 1
            if max_retries == -1:
                raise
开发者ID:B-Rich,项目名称:breve,代码行数:33,代码来源:dbutils.py


示例5: _blockUntilConditionMet

def _blockUntilConditionMet(
		getValue,
		giveUpAfterSeconds,
		shouldStopEvaluator=lambda value: bool(value),
		intervalBetweenSeconds=0.1,
		errorMessage=None):
	"""Repeatedly tries to get a value up until a time limit expires. Tries are separated by
	a time interval. The call will block until shouldStopEvaluator returns True when given the value,
	the default evaluator just returns the value converted to a boolean.
	@return A tuple, (True, value) if evaluator condition is met, otherwise (False, None)
	@raises RuntimeError if the time limit expires and an errorMessage is given.
	"""
	assert callable(getValue)
	assert callable(shouldStopEvaluator)
	assert intervalBetweenSeconds > 0.001
	SLEEP_TIME = intervalBetweenSeconds * 0.5
	startTime = _timer()
	lastRunTime = startTime
	firstRun = True  # ensure we start immediately
	while (_timer() - startTime) < giveUpAfterSeconds:
		if firstRun or (_timer() - lastRunTime) > intervalBetweenSeconds:
			firstRun = False
			lastRunTime = _timer()
			val = getValue()
			if shouldStopEvaluator(val):
				return True, val
			_sleep(SLEEP_TIME)

	else:
		if errorMessage:
			raise AssertionError(errorMessage)
		return False, None
开发者ID:MarcoZehe,项目名称:nvda,代码行数:32,代码来源:systemTestUtils.py


示例6: main

def main():
    urls = [
        # 'http://v.youku.com/v_show/id_XNzUyNDE4MTQw.html'
        # 'http://i.youku.com/u/UNTc4NzI3MjY0',
        # 'http://v.youku.com/v_show/id_XNzQ5NDAwMDIw.html?from=y1.1-2.10001-0.1-1',
        # 'http://v.youku.com/v_show/id_XNzUwMTE2MDQw.html?f=22611771',
        # 'http://v.youku.com/v_show/id_XNzQ3MjMxMTYw.html',
        'http://video.sina.com.cn/p/ent/v/m/2014-08-14/102164094039.html'
    ]
    log = util.get_logger()
    bar = ProgressBar()
    ws = WorkShop(tmin=1, tmax=2, log=log)
    dlvs = []
    for i, url in enumerate(urls):
        dlvideo = VUrlTask(url, 0, 3, './tmp', bar=bar, log=log)
        dlvs.append(dlvideo)
    try:
        ws.serve()
        ws.addTasks(dlvs)
        while len(dlvs) > 0:
            for i, dlv in enumerate(dlvs):
                if dlv.isArchived() or dlv.isError():
                    del dlvs[i]
            _sleep(1)
    except KeyboardInterrupt:
        pass
    except Exception as e:
        log.exception(e)
    finally:
        ws.setToStop()
        ws.join()
开发者ID:pkhopper,项目名称:scripts,代码行数:31,代码来源:vaxel.py


示例7: run

 def run(self):
     from random import random
     counter = 0
     while counter < self.quota:
         counter = counter + 1
         self.queue.put('%s.%d' % (self.name, counter))
         _sleep(random() * 1e-05)
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:7,代码来源:threading.py


示例8: _check

 def _check(self):
     while self.running:
         step = self._q.get()
         self._doupdate(step=step)
         self._q.task_done()
         _sleep(0.1)
     self._running = False
开发者ID:ceyzeriat,项目名称:patiencebar,代码行数:7,代码来源:patiencebar.py


示例9: preset_recall

    def preset_recall(self, preset_number, muted=False):
        """Recalls a preset on the Protea 4.24C device"""

        if not (1 <= preset_number <= 30):
            raise ValueError("Recalled preset must be between 1 and 31")

        self.write_message(21, bytes([preset_number-1, 1]))
        response = self._serial.read(10)

        if not muted:
            # This technique  is necessary because of limitations in the 4.24C,
            # in which during recall, it seems to assign values to its DSP in a
            # sequential fashion, sometimes leading to temporarily insane
            # values, such as high gains in both inputs and outputs, if the
            # previous preset had high gain in outputs and the next preset has
            # high gain in inputs.
            #
            # Furthermore, recalling the preset a second time allows us to
            # safely mute all outputs, then to recall without muting (i.e. as
            # they were saved in memory), since the input gains are already at a
            # sane level by respect to the outputs.

            _sleep(3.5)
            self.write_message(21, bytes([preset_number-1, 0]))
            response = self._serial.read(10)
开发者ID:sebleblanc,项目名称:python-protea,代码行数:25,代码来源:__init__.py


示例10: main

def main(cfg, log):
    if cfg.playlist:
        for url in cfg.urls:
            outpath, cfg.urls = parsers.getPlayListParser(url).info(url)
            cfg.outpath = pjoin(cfg.outpath, outpath)
            util.assure_path(cfg.outpath)
            with open(pjoin(cfg.outpath, 'url.txt'), 'w') as fp:
                fp.writelines([url + "\n\n"])
                for i, clip in enumerate(cfg.urls):
                    fp.writelines(["[%03d] %s\n"%(i, clip)])

    bar = ProgressBar()
    ws = WorkShop(tmin=cfg.tmin, tmax=cfg.tmax, log=log)
    dlvs = []
    for i, url in enumerate(cfg.urls):
        dlvideo = VUrlTask(url, vidfmt=cfg.vidfmt, npf=cfg.npf,
                           outpath=cfg.outpath, bar=bar, log=log)
        dlvs.append(dlvideo)
    try:
        ws.serve()
        ws.addTasks(dlvs)
        while len(dlvs) > 0:
            for i, dlv in enumerate(dlvs):
                if dlv.isArchived() or dlv.isError():
                    del dlvs[i]
            _sleep(1)
    except Exception as e:
        log.exception(e)
    finally:
        ws.setToStop()
        ws.join()
开发者ID:pkhopper,项目名称:scripts,代码行数:31,代码来源:dlvideo.py


示例11: _background_worker

 def _background_worker(self):   
     try:     
         ni = self._isec / self._psec
         itbeg = _perf_counter()    
         count = 0
         self._rflag = True
         while self._rflag:
             tbeg = _perf_counter()               
             with self._buffers_lock:
                 self._manage_buffers()
                 for (t,i), b in self._buffers.items():
                     b.incr()
                     dat = self._ssfunc(i, t, date_time=True, throw_if_data_lost=False)                    
                     if dat:
                         self._parse_data(t,i,dat)
                     if b.count == 0:
                         continue
                     if (b.count % ni) == 0:
                         #print("b.count mod interval: %i" % b.count)
                         self._handle_null_interval(t, i, b)
             count += 1
             tend = _perf_counter()
             trem = self._psec - (tend - tbeg)
             if trem < 0:
                 ## TODO :: this will create problems handling nulls as we wont be able
                 ##         to speed up by using WAIT_ADJ_DOWN (below)
                 ##         considering adjusting _psec 
                 print("WARN: _background_worker taking longer than _psec (%i) seconds"
                       % self._psec)
             _sleep( max(trem,0) * (self.WAIT_ADJ_DOWN ** self._wait_adj_down_exp) )
             if (count % ni) == 0:
                 self._tune_background_worker(count,ni,itbeg)
     finally:
         self._rflag = False
开发者ID:jeog,项目名称:TOSDataBridge,代码行数:34,代码来源:ohlc.py


示例12: _init_buffer

 def _init_buffer(self, topic, item):
     for _ in range(int(self._isec / self._psec)):
         dat = self._ssfunc(item, topic, date_time=True, throw_if_data_lost=False)
         if dat:
             return dat
         _sleep(self._psec)
     raise TOSDB_Error("failed to get any data for first interval: %s, %s" % (topic,item))
开发者ID:jeog,项目名称:TOSDataBridge,代码行数:7,代码来源:ohlc.py


示例13: get_return

    def get_return(self, wait=1, timeout=None, raise_exception=1, alt_return=None):
        """delivers the return value or (by default) echoes the exception of 
           the call job

           wait: 0=no waiting; Attribute error raised if no
                 1=waits for return value or exception
                 callable -> waits and wait()-call's while waiting for return
        """
        if not self.done and wait:
            starttime=_time()
            delay=0.0005
            while not self.done:
                if timeout:
                    remaining = starttime + timeout - _time()
                    if remaining <= 0:  #time is over
                        if raise_exception:
                            raise Empty, "return timed out"
                        else:
                            return alt_return
                    delay = min(delay * 2, remaining, .05)
                else:
                    delay = min(delay * 2, .05)
                if callable(wait): wait()
                _sleep(delay)       #reduce CPU usage by using a sleep
        if self.done==2:    #we had an exception
            exc=self.exc
            del self.exc
            if raise_exception & 1:    #by default exception is raised
                raise exc[0],exc[1],exc[2]
            else:
                return alt_return
        return self.ret
开发者ID:bhramoss,项目名称:code,代码行数:32,代码来源:recipe-491280.py


示例14: daemon

    def daemon(cls, please_stop):
        global next_ping

        Till.enabled = True
        try:
            while not please_stop:
                now = _time()
                with Till.locker:
                    if next_ping > now:
                        _sleep(min(next_ping - now, INTERVAL))
                        continue

                    next_ping = now + INTERVAL
                    work = None
                    if Till.all_timers:
                        Till.all_timers.sort(key=lambda r: r[0])
                        for i, (t, s) in enumerate(Till.all_timers):
                            if now < t:
                                work, Till.all_timers[:i] = Till.all_timers[:i], []
                                next_ping = min(next_ping, Till.all_timers[0][0])
                                break
                        else:
                            work, Till.all_timers = Till.all_timers, []

                if work:
                    for t, s in work:
                        s.go()

        except Exception, e:
            from pyLibrary.debugs.logs import Log

            Log.warning("timer shutdown", cause=e)
开发者ID:klahnakoski,项目名称:TestFailures,代码行数:32,代码来源:till.py


示例15: main

def main():
  my_cool_parser = argparse.ArgumentParser(description="Mock application to test Gooey's functionality")
  my_cool_parser.add_argument("filename", help="Name of the file you want to read")  # positional
  my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output")  # positional
  my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from')
  my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer")
  my_cool_parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit")
  my_cool_parser.add_argument('--verbose', '-v', action='count')
  my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!")
  my_cool_parser.add_argument('-r', '--recursive', choices=['yes', 'no'], help='Recurse into subfolders')
  my_cool_parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something")
  my_cool_parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes")

  print 'inside of main(), my_cool_parser =', my_cool_parser
  args = my_cool_parser.parse_args()

  print sys.argv
  print args.countdown
  print args.showtime

  start_time = _time()
  print 'Counting down from %s' % args.countdown
  while _time() - start_time < args.countdown:
    if args.showtime:
      print 'printing message at: %s' % _time()
    else:
      print 'printing message at: %s' % hashlib.md5(str(_time())).hexdigest()
    _sleep(.5)
  print 'Finished running the program. Byeeeeesss!'
开发者ID:3ancho,项目名称:Gooey,代码行数:29,代码来源:mockapp_import_argparse.py


示例16: run

 def run(self):
     from random import random
     counter = 0
     while counter < self.quota:
         counter = counter + 1
         self.queue.put("%s.%d" % (self.name, counter))
         _sleep(random() * 0.00001)
开发者ID:292388900,项目名称:restcommander,代码行数:7,代码来源:threading.py


示例17: wait

 def wait(self, timeout=None):
     if not self._is_owned():
         raise RuntimeError("cannot wait on un-acquired lock")
     waiter = Lock()
     waiter.acquire()
     self.__waiters.append(waiter)
     saved_state = self._release_save()
     try:    # restore state no matter what (e.g., KeyboardInterrupt)
         if timeout is None:
             waiter.acquire()
         else:
             # Balancing act:  We can't afford a pure busy loop, so we
             # have to sleep; but if we sleep the whole timeout time,
             # we'll be unresponsive.  The scheme here sleeps very
             # little at first, longer as time goes on, but never longer
             # than 20 times per second (or the timeout time remaining).
             endtime = _time() + timeout
             delay = 0.0005  # 500 us -> initial delay of 1 ms
             while True:
                 gotit = waiter.acquire(0)
                 if gotit:
                     break
                 remaining = endtime - _time()
                 if remaining <= 0:
                     break
                 delay = min(delay * 2, remaining, .05)
                 _sleep(delay)
             if not gotit:
                 try:
                     self.__waiters.remove(waiter)
                 except ValueError:
                     pass
     finally:
         self._acquire_restore(saved_state)
开发者ID:soulsharepj,项目名称:zdzl,代码行数:34,代码来源:gevent_threading.py


示例18: wait

    def wait(self, timeout = None):
        if not self._is_owned():
            raise RuntimeError('cannot wait on un-acquired lock')
        waiter = _allocate_lock()
        waiter.acquire()
        self.__waiters.append(waiter)
        saved_state = self._release_save()
        try:
            if timeout is None:
                waiter.acquire()
                self._note('%s.wait(): got it', self)
            else:
                endtime = _time() + timeout
                delay = 0.0005
                while True:
                    gotit = waiter.acquire(0)
                    if gotit:
                        break
                    remaining = endtime - _time()
                    if remaining <= 0:
                        break
                    delay = min(delay * 2, remaining, 0.05)
                    _sleep(delay)

                if not gotit:
                    self._note('%s.wait(%s): timed out', self, timeout)
                    try:
                        self.__waiters.remove(waiter)
                    except ValueError:
                        pass

                else:
                    self._note('%s.wait(%s): got it', self, timeout)
        finally:
            self._acquire_restore(saved_state)
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:35,代码来源:threading.py


示例19: shutdown

 def shutdown(self):
     if self._shutdown_called:
         return
     self._shutdown_called = True
     if not self._shutdown:
         self._shutdown = msg.Shutdown()
     sd = self._shutdown
     self._send_q.put(sd)
     self._main_q.put(sd)
     return
     
     if _poll_for(self, '_main_dead', timeout=sd['before_int']):
         return
         
     # currently executing something.  Try interrupting.
     for _ in range(sd['int_retries']):
         self._interrupt_main(0)
         if _poll_for(self, '_main_dead', timeout=sd['int_poll']):
             return
         
     # interrupt didn't work.  Kill ourselves
     from signal import SIGKILL
     self._log.warn("[shutdown] commiting suicide.")
     _sleep(0.1) # sleep so that the logging completes
     os.kill(os.getpid(), SIGKILL)
开发者ID:acleone,项目名称:sageserver,代码行数:25,代码来源:worker.py


示例20: wait

    def wait(self, timeout=None):
        """Wait until notified or until a timeout occurs.
        
        If the calling thread has not acquired the lock when this method is
        called, a RuntimeError is raised.
        
        This method releases the underlying lock, and then blocks until it is
        awakened by a notify() or notifyAll() call for the same condition
        variable in another thread, or until the optional timeout occurs. Once
        awakened or timed out, it re-acquires the lock and returns.
        
        When the timeout argument is present and not None, it should be a
        floating point number specifying a timeout for the operation in seconds
        (or fractions thereof).
        
        When the underlying lock is an RLock, it is not released using its
        release() method, since this may not actually unlock the lock when it
        was acquired multiple times recursively. Instead, an internal interface
        of the RLock class is used, which really unlocks it even when it has
        been recursively acquired several times. Another internal interface is
        then used to restore the recursion level when the lock is reacquired.
        
        """
        if not self._is_owned():
            raise RuntimeError("cannot wait on un-acquired lock")
        waiter = _allocate_lock()
        waiter.acquire()
        self.__waiters.append(waiter)
        saved_state = self._release_save()
        try:
            if timeout is None:
                waiter.acquire()
                self._note("%s.wait(): got it", self)
            else:
                endtime = _time() + timeout
                delay = 0.0005
                while True:
                    gotit = waiter.acquire(0)
                    if gotit:
                        break
                    remaining = endtime - _time()
                    if remaining <= 0:
                        break
                    delay = min(delay * 2, remaining, 0.05)
                    _sleep(delay)

                if not gotit:
                    self._note("%s.wait(%s): timed out", self, timeout)
                    try:
                        self.__waiters.remove(waiter)
                    except ValueError:
                        pass

                else:
                    self._note("%s.wait(%s): got it", self, timeout)
        finally:
            self._acquire_restore(saved_state)

        return
开发者ID:aevitas,项目名称:wotsdk,代码行数:59,代码来源:libthreading.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python time._time函数代码示例发布时间:2022-05-27
下一篇:
Python tiles.TilesManager类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap