本文整理汇总了Python中datetime.time.sleep方法的典型用法代码示例。如果您正苦于以下问题:Python time.sleep方法的具体用法?Python time.sleep怎么用?Python time.sleep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datetime.time
的用法示例。
在下文中一共展示了time.sleep方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _request
# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import sleep [as 别名]
def _request(payloadString):
"""Private method for requesting an arbitrary query string."""
global countRequested
global lastReqTime
if lastReqTime is not None and time.time() - lastReqTime < interReqTime:
timeToSleep = random()*(interReqTime-time.time()+lastReqTime)*2
logging.info("Sleeping for {0} seconds before request.".format(
timeToSleep))
time.sleep(timeToSleep)
logging.info("Issuing request for the following payload: {0}".format(
payloadString))
r = requests.get("{0}/{1}".format(baseUrl, payloadString))
lastReqTime = time.time()
countRequested += 1
if r.status_code == requests.codes.ok:
return r.text
else:
raise Exception("Could not process request. \
Received status code {0}.".format(r.status_code))
示例2: test_today
# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import sleep [as 别名]
def test_today(self):
import time
# We claim that today() is like fromtimestamp(time.time()), so
# prove it.
for dummy in range(3):
today = self.theclass.today()
ts = time.time()
todayagain = self.theclass.fromtimestamp(ts)
if today == todayagain:
break
# There are several legit reasons that could fail:
# 1. It recently became midnight, between the today() and the
# time() calls.
# 2. The platform time() has such fine resolution that we'll
# never get the same value twice.
# 3. The platform time() has poor resolution, and we just
# happened to call today() right before a resolution quantum
# boundary.
# 4. The system clock got fiddled between calls.
# In any case, wait a little while and try again.
time.sleep(0.1)
# It worked or it didn't. If it didn't, assume it's reason #2, and
# let the test pass if they're within half a second of each other.
if today != todayagain:
self.assertAlmostEqual(todayagain, today,
delta=timedelta(seconds=0.5))
示例3: test_today
# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import sleep [as 别名]
def test_today(self):
import time
# We claim that today() is like fromtimestamp(time.time()), so
# prove it.
for dummy in range(3):
today = self.theclass.today()
ts = time.time()
todayagain = self.theclass.fromtimestamp(ts)
if today == todayagain:
break
# There are several legit reasons that could fail:
# 1. It recently became midnight, between the today() and the
# time() calls.
# 2. The platform time() has such fine resolution that we'll
# never get the same value twice.
# 3. The platform time() has poor resolution, and we just
# happened to call today() right before a resolution quantum
# boundary.
# 4. The system clock got fiddled between calls.
# In any case, wait a little while and try again.
time.sleep(0.1)
# It worked or it didn't. If it didn't, assume it's reason #2, and
# let the test pass if they're within half a second of each other.
self.assertTrue(today == todayagain or
abs(todayagain - today) < timedelta(seconds=0.5))
示例4: test_today
# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import sleep [as 别名]
def test_today(self):
import time
# We claim that today() is like fromtimestamp(time.time()), so
# prove it.
for dummy in range(3):
today = self.theclass.today()
ts = time.time()
todayagain = self.theclass.fromtimestamp(ts)
if today == todayagain:
break
# There are several legit reasons that could fail:
# 1. It recently became midnight, between the today() and the
# time() calls.
# 2. The platform time() has such fine resolution that we'll
# never get the same value twice.
# 3. The platform time() has poor resolution, and we just
# happened to call today() right before a resolution quantum
# boundary.
# 4. The system clock got fiddled between calls.
# In any case, wait a little while and try again.
time.sleep(0.1)
# It worked or it didn't. If it didn't, assume it's reason #2, and
# let the test pass if they're within half a second of each other.
self.failUnless(today == todayagain or
abs(todayagain - today) < timedelta(seconds=0.5))