本文整理汇总了Python中timer.Timer方法的典型用法代码示例。如果您正苦于以下问题:Python timer.Timer方法的具体用法?Python timer.Timer怎么用?Python timer.Timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer
的用法示例。
在下文中一共展示了timer.Timer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_attributes
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def test_attributes(context):
# Timer1: periodic interval 0.8 sec
timer1 = timer.Timer(
interval=0.8,
expire_function=context.timer1_expired)
# Timer2: one-shot interval 0.7 sec
timer2 = timer.Timer(
interval=0.7,
expire_function=context.timer2_expired,
periodic=False)
assert timer1.running() is True
assert timer1.interval() == pytest.approx(0.8)
assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer1.remaining_time_str())
assert timer2.running() is True
assert timer2.interval() == pytest.approx(0.7)
assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer2.remaining_time_str())
time.sleep(1.0)
timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert timer1.running() is True
assert timer1.interval() == pytest.approx(0.8)
assert re.match(r"0\.[0-9][0-9][0-9][0-9][0-9][0-9] secs", timer1.remaining_time_str())
assert timer2.running() is False
assert timer2.interval() == pytest.approx(0.7)
assert timer2.remaining_time_str() == "Stopped"
示例2: train_model
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def train_model(self, max_iters):
"""Network training loop."""
last_snapshot_iter = -1
timer = Timer()
while self.solver.iter < max_iters:
timer.tic()
self.solver.step(1)
print 'fc9_1:',sorted(self.solver.net.params['fc9_1'][0].data[0])[-1]
#print 'fc9:',sorted(self.solver.net.params['fc9'][0].data[0])[-1]
#print 'fc7:',sorted(self.solver.net.params['fc7'][0].data[0])[-1]
#print 'fc6:',sorted(self.solver.net.params['fc6'][0].data[0])[-1]
#print 'fc9:',(self.solver.net.params['fc9'][0].data[0])[0]
#print 'fc7:',(self.solver.net.params['fc7'][0].data[0])[0]
#print 'fc6:',(self.solver.net.params['fc6'][0].data[0])[0]
#print 'conv5_3:',self.solver.net.params['conv5_3'][0].data[0][0][0]
#print 'conv5_2:',self.solver.net.params['conv5_2'][0].data[0][0][0]
#print 'conv5_1:',self.solver.net.params['conv5_1'][0].data[0][0][0]
#print 'conv4_3:',self.solver.net.params['conv4_3'][0].data[0][0][0]
#print 'fc9:',self.solver.net.params['fc9'][0].data[0][0]
timer.toc()
if self.solver.iter % (10 * self.solver_param.display) == 0:
print 'speed: {:.3f}s / iter'.format(timer.average_time)
示例3: wait_for_task_to_complete
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def wait_for_task_to_complete(self, timeout=600):
timer = Timer()
timer.start()
while True:
timer.print_time_elapsed()
print("Checking status of task.")
if timer.has_timeout(timeout):
raise TimeOutError("Task timed out after " + str(timeout) +
" seconds.")
if self.is_task_completed():
print("Task Completed!")
return
timer.sleep(3)
示例4: preload
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def preload(self):
self.ncls = {k: np.random.choice([0,1], p=pro) for k, pro in self.pro_dict.items()}
self.choices = {k: random.randint(0, len(self.sample_dict[k][ncl]) - 1) for k, ncl in self.ncls.items()}
self.loaded = {}
indexs = [self.sample_dict[self.patch_list[i][0] + 1]\
[self.ncls[self.patch_list[i][0] + 1]]\
[self.choices[self.patch_list[i][0] + 1]]\
[0] for i in range(self.get_num_samples())]
indexs = set(indexs)
load_timer = Timer()
load_timer.tic()
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
for blob in executor.map(lambda i: (i,self.dataloader[i]), indexs):
self.loaded[blob[0]] = blob[1]
print "re-prior crop: %f s" % load_timer.toc(average=False)
示例5: apply_refraction
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def apply_refraction(self, us_time):
"""Implements a refractory period for each pixel.
Does not modify instance data
In other words, if an event occurs within 'us_time' microseconds of
a previous event at the same pixel, then the second event is removed
us_time: time in microseconds
"""
t0 = np.ones((self.width, self.height)) - us_time - 1
valid_indices = np.ones(len(self.data), np.bool_)
#with timer.Timer() as ref_timer:
i = 0
for datum in np.nditer(self.data):
datum_ts = datum['ts'].item(0)
datum_x = datum['x'].item(0)
datum_y = datum['y'].item(0)
if datum_ts - t0[datum_x, datum_y] < us_time:
valid_indices[i] = 0
else:
t0[datum_x, datum_y] = datum_ts
i += 1
#print 'Refraction took %s seconds' % ref_timer.secs
return self.data[valid_indices.astype('bool')]
示例6: submit_order_by_time
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def submit_order_by_time(self, buy_time, retry=4, interval=5):
"""定时提交商品订单
重要:该方法只适用于普通商品的提交订单,事先需要先将商品加入购物车并勾选✓。
:param buy_time: 下单时间,例如:'2018-09-28 22:45:50.000'
:param retry: 下单重复执行次数,可选参数,默认4次
:param interval: 下单执行间隔,可选参数,默认5秒
:return:
"""
t = Timer(buy_time=buy_time)
t.start()
for count in range(1, retry + 1):
logger.info('第[%s/%s]次尝试提交订单', count, retry)
if self.submit_order():
break
logger.info('休息%ss', interval)
time.sleep(interval)
else:
logger.info('执行结束,提交订单失败!')
示例7: exec_seckill_by_time
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def exec_seckill_by_time(self, sku_ids, buy_time, retry=4, interval=4, num=1, fast_mode=True):
"""定时抢购
:param sku_ids: 商品id,多个商品id用逗号进行分割,如"123,456,789"
:param buy_time: 下单时间,例如:'2018-09-28 22:45:50.000'
:param retry: 抢购重复执行次数,可选参数,默认4次
:param interval: 抢购执行间隔,可选参数,默认4秒
:param num: 购买数量,可选参数,默认1个
:param fast_mode: 快速模式:略过访问抢购订单结算页面这一步骤,默认为 True
:return:
"""
items_dict = parse_sku_id(sku_ids=sku_ids)
logger.info('准备抢购商品:%s', list(items_dict.keys()))
t = Timer(buy_time=buy_time)
t.start()
for sku_id in items_dict:
logger.info('开始抢购商品:%s', sku_id)
self.exec_seckill(sku_id, retry, interval, num, fast_mode)
示例8: myFunction
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def myFunction():
# We create this context so that we can crawl
# https sites
myssl = ssl.create_default_context();
myssl.check_hostname=False
myssl.verify_mode=ssl.CERT_NONE
with Timer() as t:
req = Request('https://tutorialedge.net', headers={'User-Agent': 'Mozilla/5.0'})
response = urlopen(req, context=myssl)
print("Elapsed Time: {} seconds".format(t.elapsed))
示例9: test_oneshot
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def test_oneshot(context):
# Timer1: interval 0.8 sec (expires 1x in 2.0 sec), started in constructor
# Rely on default values for start parameter
_timer1 = timer.Timer(
interval=0.8,
expire_function=context.timer1_expired,
periodic=False)
# Timer2: interval 2.2 sec (expires 0x in 2.0 sec), started outside constructor
timer2 = timer.Timer(
interval=2.2,
expire_function=context.timer1_expired,
periodic=False,
start=False)
timer2.start()
# Timer3: interval 2.5 sec (expires 0x in 2.0 sec), never started
_timer3 = timer.Timer(
interval=2.5,
expire_function=context.timer3_expired,
periodic=False,
start=False)
# Timer4: interval 0.8 sec (same as timer1, expires 1x in 2.0 sec), started outside constructor
timer4 = timer.Timer(
interval=0.8,
expire_function=context.timer4_expired,
periodic=False,
start=False)
timer4.start()
# Timer5: interval 1.4 sec (expires 1x in 2.0 sec), not started
_timer5 = timer.Timer(
interval=1.4,
expire_function=context.timer5_expired,
periodic=False,
start=False)
time.sleep(2.0)
timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert context.timer1_expired_count == 1
assert context.timer2_expired_count == 0
assert context.timer3_expired_count == 0
assert context.timer4_expired_count == 1
assert context.timer5_expired_count == 0
示例10: test_start_stop
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def test_start_stop(context):
# Timer1: interval 0.8 sec (expires 2x in 2.0 sec), started in constructor
timer1 = timer.Timer(
interval=0.8,
expire_function=context.timer1_expired)
# Start timer1 when it is already running
timer1.start()
# Timer1: one-shot interval 0.6 sec (expires 3x in 2.0 sec), started outside constructor
timer2 = timer.Timer(
interval=0.6,
expire_function=context.timer2_expired,
periodic=True,
start=False)
timer2.start()
# Timer3: one-shot interval 0.8 sec (expires 1x in 2.0 sec), started in constructor
timer3 = timer.Timer(
interval=0.8,
expire_function=context.timer3_expired,
periodic=True,
start=True)
# Stop timer3 (will not expire)
timer3.stop()
time.sleep(2.0)
timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert context.timer1_expired_count == 2
assert context.timer2_expired_count == 3
assert context.timer3_expired_count == 0
示例11: test_remaining_time
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def test_remaining_time(context):
# Haven't created any timers yet
time_to_next_expire = timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert time_to_next_expire is None
# Timer1: periodic interval 0.8 sec
timer1 = timer.Timer(
interval=0.8,
expire_function=context.timer1_expired)
# Timer2: one-shot interval 0.8 sec
_timer2 = timer.Timer(
interval=0.8,
expire_function=context.timer2_expired,
periodic=False)
time.sleep(2.0)
# Now is 2.0
time_to_next_expire = timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert context.timer1_expired_count == 2 # Expired at 0.8 and 1.6. Next expiry at 2.4
assert context.timer2_expired_count == 1 # Expired at 0.8. No next expiry.
assert time_to_next_expire == pytest.approx(0.4, abs=0.1)
time.sleep(0.5)
# Now is 2.5
context.clear_counters()
time_to_next_expire = timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert context.timer1_expired_count == 1 # Expired at 2.4. Next expiry at 3.2.
assert context.timer2_expired_count == 0 # Not running.
assert time_to_next_expire == pytest.approx(0.7, abs=0.1)
# Stop timer1. At this point no timer is running, so there no time_to_next_expire.
timer1.stop()
time_to_next_expire = timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert time_to_next_expire is None
time.sleep(1.0)
context.clear_counters()
time_to_next_expire = timer.TIMER_SCHEDULER.trigger_all_expired_timers()
assert time_to_next_expire is None
assert context.timer1_expired_count == 0 # Not running
assert context.timer2_expired_count == 0 # Not running
示例12: cli_details_table
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def cli_details_table(self):
tab = table.Table(separators=False)
tab.add_rows([
["Name", self.name],
["Passive", self._passive],
["Running", self.is_running()],
["System ID", utils.system_id_str(self.system_id)],
["Configured Level", self._configured_level_symbol],
["Leaf Only", self._leaf_only],
["Leaf 2 Leaf", self.leaf_2_leaf],
["Top of Fabric Flag", self._top_of_fabric_flag],
["Zero Touch Provisioning (ZTP) Enabled", self.zero_touch_provisioning_enabled()],
["ZTP FSM State", self.fsm.state.name],
["ZTP Hold Down Timer", self._hold_down_timer.remaining_time_str()],
["ZTP Hold Down Timer", self._hold_down_timer.remaining_time_str()],
["Highest Available Level (HAL)", self._highest_available_level],
["Highest Adjacency Three-way (HAT)", self.highest_adjacency_three_way],
["Level Value", self.level_value_str()],
["Receive LIE IPv4 Multicast Address", self.rx_lie_ipv4_mcast_address],
["Transmit LIE IPv4 Multicast Address", self._tx_lie_ipv4_mcast_address],
["Receive LIE IPv6 Multicast Address", self.rx_lie_ipv6_mcast_address],
["Transmit LIE IPv6 Multicast Address", self._tx_lie_ipv6_mcast_address],
["Receive LIE Port", self._rx_lie_port],
["Transmit LIE Port", self.tx_lie_port],
["LIE Send Interval", "{} secs".format(self.lie_send_interval_secs)],
["Receive TIE Port", self.rx_flood_port],
["Kernel Route Table", self._kernel_route_table],
["Originating South-bound Default Route", self._originating_default],
["Flooding Reduction Enabled", self.floodred_enabled],
["Flooding Reduction Redundancy", self.floodred_redundancy],
["Flooding Reduction Similarity", self.floodred_similarity],
["Flooding Reduction Node Random", self.floodred_node_random],
])
return tab
示例13: start_defer_spf_timer
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def start_defer_spf_timer(self):
self._defer_spf_timer = timer.Timer(
interval=self.MIN_SPF_INTERVAL,
expire_function=self.defer_spf_timer_expired,
periodic=False,
start=True)
示例14: run
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def run(self):
self._lie_tx_ipv4_socket = self.create_socket_ipv4_tx_mcast(
multicast_address=self._tx_lie_ipv4_mcast_address,
port=self._tx_lie_port,
loopback=self.node.engine.ipv4_multicast_loopback)
self._lie_tx_ipv6_socket = self.create_socket_ipv6_tx_mcast(
multicast_address=self._tx_lie_ipv6_mcast_address,
port=self._tx_lie_port,
loopback=self.node.engine.ipv6_multicast_loopback)
self._lie_rx_ipv4_handler = udp_rx_handler.UdpRxHandler(
interface_name=self.physical_interface_name,
local_port=self._rx_lie_port,
ipv4=True,
multicast_address=self._rx_lie_ipv4_mcast_address,
remote_address=None,
receive_function=self.receive_lie_message,
log=self._rx_log,
log_id=self._log_id)
self._lie_rx_ipv6_handler = udp_rx_handler.UdpRxHandler(
interface_name=self.physical_interface_name,
local_port=self._rx_lie_port,
ipv4=False,
multicast_address=self._rx_lie_ipv6_mcast_address,
remote_address=None,
receive_function=self.receive_lie_message,
log=self._rx_log,
log_id=self._log_id)
self._flood_rx_ipv4_handler = None
self._flood_tx_ipv4_socket = None
self._one_second_timer = timer.Timer(
1.0,
lambda: self.fsm.push_event(self.Event.TIMER_TICK))
示例15: __init__
# 需要导入模块: import timer [as 别名]
# 或者: from timer import Timer [as 别名]
def __init__(self, log_name='logs.txt'):
self.cur_epoch = 0
# timer
self.tot_timer = Timer()
self.gpu_timer = Timer()
self.read_timer = Timer()
# logger
self.logger = colorlogger(cfg.log_dir, log_name=log_name)