计算运行消耗时间
    @timeit
    def test():
        time.sleep(1)
490548
def timeit(func):
    '''
    
    '''

    def wapper(*args, **kwargs):
        _start = time.time()
        retval = func(*args, **kwargs)
        _end = time.time()
        logger.info('function %s() used : %.6f s' % (func.__name__, _end - _start))
        return retval

    return wapper
259212
public int check(TimeUnit timeUnit, long count) {
        
        int pollPeriodMillis = getPollPeriodMillis();
        long startTime = System.currentTimeMillis();
        long expireTime = startTime + timeUnit.toMillis(count);
        int iteration = 0;
        while(true) {
            iteration++;
            try {
                validate();
            } catch (Throwable t) {
                propagateAsError(t);
            }
            
            sleepUntil(startTime + (pollPeriodMillis * iteration));

            if ( System.currentTimeMillis() >= expireTime) {
                break;
            }
        }
        
        return iteration;
    }
1318524
function _check(asyncClient, route) {
    return new Promise((resolve, reject) => {
        // 有问题时直接执行真实的fetch方法
        if (!asyncClient) {
            return reject(RESULT.NO_ASYNC_CLIENT);
        }

        // 如果远程服务未启动也需要放弃async
        if (!route) {
            return reject(RESULT.NO_ROUTE);
        }

        let i = 0;
        let checkT;

        function checkConnect() {
            if (asyncClient.isConnected()) {
                // 如果已经连接成功，则清除定时器，并返回
                if (checkT) {
                    clearTimeout(checkT);
                }

                resolve();
            } else if (i > 9) {
                // 如果重试次数大于了10次，也终止，清除定时器，并返回
                if (checkT) {
                    clearTimeout(checkT);
                }

                alert(`mockstar async 服务未启动！请检查 ${asyncClient.getURI()} 是否已启动`);
                reject(RESULT.NOT_CONNECTED);
            } else {
                i++;
                // 使之异步，避免 websocket 还未连接成功
                checkT = setTimeout(() => {
                    checkConnect();
                }, 10);
            }
        }

        checkConnect();
    });
}
396793
def monitor(self, timeout):
        

        def check(self, timeout):
            time.sleep(timeout)
            self.stop()
        wather = threading.Thread(target=check)
        wather.setDaemon(True)
        wather.start()
1131043
def timeit(method):
    """"""

    def wrapper(*args, **kwargs):
        start = time.time()
        result = method(*args, **kwargs)
        end = time.time()

        click.echo('Cost {}s'.format(int(end-start)))
        return result

    return wrapper
1166008
def work(self):
        
        import time
        for val in range(200):
            time.sleep(0.1)
            self.sigUpdate.emit(val + 1)
431832
protected function wait()
    {
        $timer          = 0;
        $timeout        = $this->getWaitTimeout();
        $interval       = $this->checkInterval;
        $intervalSecond = $this->checkInterval / 1000;

        while ($timer <= $timeout) {
            // 等到了可用的空闲资源
            if ($res = $this->getFreeQueue()->pop()) {
                return $res;
            }

            $timer += $interval;
            // 无空闲资源可用， 进入等待状态
            Coroutine::sleep($intervalSecond);
        }

        throw new \RuntimeException("No resources available. Waiting timeout($timeout ms) for get resource.");
    }
905204
def timed (log=sys.stderr, limit=2.0):
    """"""
    return lambda func: timeit(func, log, limit)
1219191
public static void main(String[] args) throws Exception {
        while( true ) {
           Thread.sleep(1000*60*5);
           System.out.println("Test wakeup");
        }
    }
1265027
@Override
	public void run() {
		ThriftConnectionHandle<T> connection;
		long tmp;
		long nextCheckInMs = this.maxConnectionAge;

		int partitionSize = this.thriftConnectionPartition.getAvailableConnections();
		long currentTime = System.currentTimeMillis();
		for (int i = 0; i < partitionSize; i++) {
			try {
				connection = this.thriftConnectionPartition.poolFreeConnection();

				if (connection != null) {
					connection.setOriginatingPartition(this.thriftConnectionPartition);

					tmp = this.maxConnectionAge - (currentTime - connection.getConnectionCreationTimeInMs());

					if (tmp < nextCheckInMs) {
						nextCheckInMs = tmp;
					}

					// 判断连接是否过期
					if (connection.isExpired(currentTime)) {
						// 关闭连接
						closeConnection(connection);
						continue;
					}

					if (lifoMode == ServiceOrder.LIFO) {
						if (!(connection.getConnectionPartition().getFreeConnections().offer(connection))) {
							connection.internalClose();
						}
					} else {
						this.thriftConnectionPool.putConnectionBackInPartition(connection);
					}
					// 避免cpu使用率过高 进行一段时间休眠
					Thread.sleep(20L);
				}
			} catch (Throwable e) {
				logger.error("Connection max age thread exception.", e);
			}
		}

	}
1299170
public void run() {
        if (maxTime < 0) {
            return;
        }
        long timeMillis = (long)maxTime * 60 * 1000;
        endTime = new Date((new Date()).getTime() + timeMillis);
        while (!cancel && endTime.after(new Date())) {
            try {
                Thread.sleep(1000);
            }
            catch (InterruptedException e) {
                cancel = true;
            }
        }
        if (!cancel && !endTime.after(new Date())) {
            session.removeAttribute(key);
        }
    }
658982
def timeit(func, *args, **kwargs):
    
    start_time = time.time()
    res = func(*args, **kwargs)
    timing = time.time() - start_time
    return res, timing
505903
private static void method() {
//		StopWatch stopWatch = new LoggingStopWatch();
		Split split = SimonManager.getStopwatch("codeBlock2").start();

		try {
			// the code block being timed - this is just a dummy example
			long sleepTime = (long) (Math.random() * 1000L);
			Thread.sleep(sleepTime);
			if (sleepTime > 500L) {
				throw new Exception("Throwing exception");
			}

			split.stop("success");
//			stopWatch.stop("codeBlock2.success", "Sleep time was < 500 ms");
		} catch (Exception e) {
			split.stop("failure");
//			stopWatch.stop("codeBlock2.failure", "Exception was: " + e);
		}
	}
665996
def run(self, resources):
        
        hwman = resources['connection']
        con = hwman.hwman.controller()
        test_interface = con.test_interface()
        try:
            test_interface.synchronize_clock()
            print('Time currently set at %s' % test_interface.current_time_str())
        except:
            raise ArgumentError('Error setting RTC time, check if controller actually has RTC or if iotile-support-lib-controller-3 is updated')
922718
def wait(self, timeout=None):
        
        try:
            if timeout:
                gevent.sleep(timeout)
            else:
                while True:
                    gevent.sleep(1000)
        except (KeyboardInterrupt, SystemExit, Exception):
            pass
1287308
final public function check() : bool
    {
        if(empty($this->getTimestamp())){
            throw new InvalidTimestampException('请设置参数:' . $this->input_timestamp);
        }
        if(date("Y-m-d H:i:s", strtotime($this->getTimestamp())) != $this->getTimestamp()){
            throw new InvalidTimestampException('参数格式错误:' . $this->input_timestamp);
        }
        if(strtotime($this->getTimestamp()) < time() - $this->lifetime){
            throw new InvalidTimestampException('生成的请求参数已经超过有效期');
        }
        return true;
    }
272925
function timeTaken(callback) {
  if (typeof callback !== 'function') throw new Error('callback 必须为可执行的函数');
  console.time('timeTaken');
  const r = callback();
  console.timeEnd('timeTaken');

  return r;
}