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


Python time._time函数代码示例

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


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

示例1: clear_headspace

    def clear_headspace(self):
        """
        Run "headspace" gas to pass headspace volume * 5 L of air.
        """
        headspace = self.reactor_ctx.vessel_capacity - self.volume
        t_min = headspace / self.reactor_ctx.main_gas_max * self.test_ctx.hs_purge_factor

        self.app.login()
        self.app.setph(2, 0, 0)
        self.app.setdo(2, 0, 0)
        self.set_gas(1, self.reactor_ctx.main_gas_max)

        now = _time()
        end = now + 60 * t_min
        while True:
            left = end - _time()
            left = max(left, 0)
            if left < 15:
                if left:
                    self.print("\r                                          ", end="")
                    self.print("\rHeadspace purge: %s seconds remain" % (int(end - _time())), end="")
                    _sleep(left)
                break
            else:
                _sleep(int(left) % 15)
                self.print("\r                                          ", end="")
                self.print("\rHeadspace purge: %s seconds remain" % (int(end - _time())), end="")
                _sleep(1)

        self.print("\nPurge Finished")
        self.app.login()
        self.set_gas(2, 0)
开发者ID:nitetrain8,项目名称:pbslib,代码行数:32,代码来源:runner.py

示例2: 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

示例3: put

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

        If optional args `block` is True and `timeout` is None (the
        default), block if necessary until a free slot is
        available. If `timeout` is a positive number, it blocks at
        most `timeout` seconds and raises the ``Full`` exception if no
        free slot was available within that time.  Otherwise (`block`
        is false), put an item on the queue if a free slot is
        immediately available, else raise the ``Full`` exception
        (`timeout` is ignored in that case).
        """

        self.not_full.acquire()
        try:
            if not block:
                if self._full():
                    raise Full
            elif timeout is None:
                while self._full():
                    self.not_full.wait()
            else:
                if timeout < 0:
                    raise ValueError("'timeout' must be a positive number")
                endtime = _time() + timeout
                while self._full():
                    remaining = endtime - _time()
                    if remaining <= 0.0:
                        raise Full
                    self.not_full.wait(remaining)
            self._put(item)
            self.not_empty.notify()
        finally:
            self.not_full.release()
开发者ID:Noura,项目名称:storytime,代码行数:34,代码来源:queue.py

示例4: 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

示例5: acquire

 def acquire(self, blocking=True, timeout=None):
     if not blocking and timeout is not None:
         raise ValueError("can't specify timeout for non-blocking acquire")
     rc = False
     endtime = None
     self._cond.acquire()
     while self._value == 0:
         if not blocking:
             break
         if __debug__:
             self._note("%s.acquire(%s): blocked waiting, value=%s",
                        self, blocking, self._value)
         if timeout is not None:
             if endtime is None:
                 endtime = _time() + timeout
             else:
                 timeout = endtime - _time()
                 if timeout <= 0:
                     break
         self._cond.wait(timeout)
     else:
         self._value = self._value - 1
         if __debug__:
             self._note("%s.acquire: success, value=%s",
                        self, self._value)
         rc = True
     self._cond.release()
     return rc
开发者ID:ChowZenki,项目名称:kbengine,代码行数:28,代码来源:threading.py

示例6: 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

示例7: put

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

        If optional args 'block' is true and 'timeout' is None (the default),
        block if necessary until a free slot is available. If 'timeout' is
        a non-negative number, it blocks at most 'timeout' seconds and raises
        the Full exception if no free slot was available within that time.
        Otherwise ('block' is false), put an item on the queue if a free slot
        is immediately available, else raise the Full exception ('timeout'
        is ignored in that case).
        """
        self.not_full.acquire()
        try:
            if self.maxsize > 0:
                if not block:
                    if self._qsize() == self.maxsize:
                        raise Queue.Full
                elif timeout is None:
                    while self._qsize() == self.maxsize:
                        self.not_full.wait()
                elif timeout < 0:
                    raise ValueError("'timeout' must be a non-negative number")
                else:
                    endtime = _time() + timeout
                    while self._qsize() == self.maxsize:
                        remaining = endtime - _time()
                        if remaining <= 0.0:
                            raise Queue.Full
                        self.not_full.wait(remaining)
            self._put(item)
            self.unfinished_tasks += 1
            self.not_empty.notify()
        finally:
            self.not_full.release()
开发者ID:Cesar456,项目名称:pritunl,代码行数:34,代码来源:none_queue.py

示例8: _expect_with_poll

 def _expect_with_poll(self, expect_list, timeout=None):
     re = None
     expect_list = expect_list[:]
     indices = range(len(expect_list))
     for i in indices:
         while not hasattr(expect_list[i], 'search'):
             if not re:
                 import re
             expect_list[i] = re.compile(expect_list[i])
     call_timeout = timeout
     if timeout is not None:
         time_start = _time()
     self.process_rawq()
     m = None
     for i in indices:
         m = expect_list[i].search(self.cookedq)
         while m:
             e = m.end()
             text = self.cookedq[:e]
             self.cookedq = self.cookedq[e:]
             break
     if not m:
         poller = select.poll()
         poll_in_or_priority_flags = select.POLLIN | select.POLLPRI
         poller.register(self, poll_in_or_priority_flags)
         while not m:
             while not self.eof:
                 try:
                     ready = poller.poll(None if timeout is None else 1000*call_timeout)
                 except select.error as e:
                     if timeout is not None:
                         elapsed = _time() - time_start
                         call_timeout = timeout - elapsed
                     continue
                     raise
                 for (fd, mode) in ready:
                     while mode & poll_in_or_priority_flags:
                         self.fill_rawq()
                         self.process_rawq()
                         while True:
                             for i in indices:
                                 m = expect_list[i].search(self.cookedq)
                                 while m:
                                     e = m.end()
                                     text = self.cookedq[:e]
                                     self.cookedq = self.cookedq[e:]
                                     break
                 while timeout is not None:
                     elapsed = _time() - time_start
                     if elapsed >= timeout:
                         break
                     call_timeout = timeout - elapsed
                     continue
         poller.unregister(self)
     if m:
         return (i, m, text)
     text = self.read_very_lazy()
     if not text and self.eof:
         raise EOFError
     return (-1, None, text)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:60,代码来源:telnetlib.py

示例9: _expect_with_select

 def _expect_with_select(self, list, timeout=None):
     re = None
     list = list[:]
     indices = range(len(list))
     for i in indices:
         while not hasattr(list[i], 'search'):
             if not re:
                 import re
             list[i] = re.compile(list[i])
     if timeout is not None:
         time_start = _time()
     while True:
         self.process_rawq()
         for i in indices:
             m = list[i].search(self.cookedq)
             while m:
                 e = m.end()
                 text = self.cookedq[:e]
                 self.cookedq = self.cookedq[e:]
                 return (i, m, text)
         if self.eof:
             break
         if timeout is not None:
             elapsed = _time() - time_start
             if elapsed >= timeout:
                 break
             s_args = ([self.fileno()], [], [], timeout - elapsed)
             (r, w, x) = select.select(*s_args)
             if not r:
                 break
         self.fill_rawq()
     text = self.read_very_lazy()
     if not text and self.eof:
         raise EOFError
     return (-1, None, text)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:35,代码来源:telnetlib.py

示例10: put

 def put(self, item, block=True, timeout=None):
     """
     look at Queue.LifoQueue doc; instead of raising Queue.Full exception,
     removes least recently added item and puts new item.
     """
     with self.not_full:
         if self.maxsize > 0:
             if not block:
                 if self._qsize() == self.maxsize:
                     # this replaces "raise Queue.Full"
                     self.queue.pop(0)
             elif timeout is None:
                 while self._qsize() == self.maxsize:
                     self.not_full.wait()
             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:
                         # this replaces "raise Queue.Full"
                         self.queue.pop(0)
                     self.not_full.wait(remaining)
         self._put(item)
         self.unfinished_tasks += 1
         self.not_empty.notify()
开发者ID:shvar,项目名称:redfs,代码行数:27,代码来源:auth_tokens.py

示例11: _read_until_with_select

 def _read_until_with_select(self, match, timeout=None):
     n = len(match)
     self.process_rawq()
     i = self.cookedq.find(match)
     if i >= 0:
         i = i + n
         buf = self.cookedq[:i]
         self.cookedq = self.cookedq[i:]
         return buf
     s_reply = ([self], [], [])
     s_args = s_reply
     if timeout is not None:
         s_args = s_args + (timeout,)
         time_start = _time()
     while not self.eof:
         while select.select(*s_args) == s_reply:
             i = max(0, len(self.cookedq) - n)
             self.fill_rawq()
             self.process_rawq()
             i = self.cookedq.find(match, i)
             if i >= 0:
                 i = i + n
                 buf = self.cookedq[:i]
                 self.cookedq = self.cookedq[i:]
                 return buf
             while timeout is not None:
                 elapsed = _time() - time_start
                 if elapsed >= timeout:
                     break
                 s_args = s_reply + (timeout - elapsed,)
                 continue
     return self.read_very_lazy()
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:32,代码来源:telnetlib.py

示例12: resolve

def resolve(host, port=80, host_string='', path=None, timeout=1):
    import socket
    sock = socket.socket(socket.AF_INET)
    sock.settimeout(timeout or None)
    package = 'GET / HTTP/1.1\n'
    if path:
        if not path.startswith('/'):
            path = '/' + path
        package = 'GET %s HTTP/1.1\n' % path
    if host_string:
        package += 'Host: %s\n' % host_string
        package += 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0\n'
        package += 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n'
    package += '\n'
    try:
        start = _time()
        sock.connect((host, port))
        sock.send(package)
        data = sock.recv(1024)
        if not data or len(data) < 1:
            return None
        print data
        return _time() - start
    except Exception as e:
        return None
    finally:
        if sock:
            sock.close()
开发者ID:pkhopper,项目名称:scripts,代码行数:28,代码来源:ipscanner.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: put

    def put(self, item, block = True, timeout = None):
        self.not_full.acquire()
        try:
            if not block:
                if self._full():
                    raise Full
            elif timeout is None:
                while self._full():
                    self.not_full.wait()

            else:
                if timeout < 0:
                    raise ValueError("'timeout' must be a positive number")
                endtime = _time() + timeout
                while self._full():
                    remaining = endtime - _time()
                    if remaining <= 0.0:
                        raise Full
                    self.not_full.wait(remaining)

            self._put(item)
            self.unfinished_tasks += 1
            self.not_empty.notify()
        finally:
            self.not_full.release()
开发者ID:Pluckyduck,项目名称:eve,代码行数:25,代码来源:Queue.py

示例15: join

 def join(self, timeout=None):
     assert self.__initialized, "Thread.__init__() not called"
     assert self.__started, "cannot join thread before it is started"
     assert self is not currentThread(), "cannot join current thread"
     if __debug__:
         if not self.__stopped:
             self._note("%s.join(): waiting until thread stops", self)
     self.__block.acquire()
     if timeout is None:
         while not self.__stopped:
             self.__block.wait()
         if __debug__:
             self._note("%s.join(): thread stopped", self)
     else:
         deadline = _time() + timeout
         while not self.__stopped:
             delay = deadline - _time()
             if delay <= 0:
                 if __debug__:
                     self._note("%s.join(): timed out", self)
                 break
             self.__block.wait(delay)
         else:
             if __debug__:
                 self._note("%s.join(): thread stopped", self)
     self.__block.release()
开发者ID:Lamouse,项目名称:Evolutionary-Creativity,代码行数:26,代码来源:threading.py


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