本文整理汇总了Python中utils.Logger.warning方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.warning方法的具体用法?Python Logger.warning怎么用?Python Logger.warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Logger
的用法示例。
在下文中一共展示了Logger.warning方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_receive
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import warning [as 别名]
def handle_receive(self, packet, time):
if isinstance(packet, AckPacket):
Rn = packet.request_number
self.last_n_req_nums.append(Rn)
if len(self.last_n_req_nums) > TCPReno.MAX_DUPLICATES:
self.last_n_req_nums.pop(0)
Sn, Sb, Sm = self.host.sequence_nums
cwnd = self.host.cwnd
if self.last_drop is None or \
time - self.last_drop > TCPReno.TIMEOUT_TOLERANCE:
if len(self.last_n_req_nums) == TCPReno.MAX_DUPLICATES and \
all(num == Rn for num in self.last_n_req_nums):
# If we've had duplicate ACKs, then enter fast retransmit.
self.ssthresh = max(self.host.cwnd / 2, TCPReno.INITIAL_CWND)
self.set_window_size(time, self.ssthresh)
Logger.warning(time, "Duplicate ACKs received for flow %s." % self.host.flow[0])
self.last_drop = time
if self.ss:
self.set_window_size(time, cwnd + 1)
if self.host.cwnd >= self.ssthresh:
self.ss = False
Logger.info(time, "SS phase over for Flow %s. CA started." % (self.host.flow[0]))
elif Rn > Sb:
# If we are in Congestion Avoidance mode, we wait for an RTT to
# increase the window size, rather than doing it on ACK.
self.set_window_size(time, cwnd + 1. / cwnd)
示例2: receive
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import warning [as 别名]
def receive(self, packet, time):
"""
Handles receipt of a packet.
Args:
packet (Packet): The packet.
time (float): Time the packet was received
"""
Logger.info(time, "%s received packet %s" % (self, packet))
# Get the appropriate routing table
routing_table = self.get_routing_table()
# Update the current routing table with the routing packet
if isinstance(packet, StaticRoutingPacket):
self.handle_routing_packet(packet, dynamic=False)
elif isinstance(packet, DynamicRoutingPacket):
self.handle_routing_packet(packet, dynamic=True)
# Route the packet
elif isinstance(packet, AckPacket) or isinstance(packet, Packet):
if not routing_table:
Logger.warning(time, "%s dropped packet %s, no routing table. "
"Creating one now." % (self, packet))
self.create_routing_table(self.dynamicEnabled)
return
elif packet.dest.id not in routing_table:
# TODO: should we keep a packet queue for packets w/o dest.?
Logger.warning(time, "%s dropped packet %s, dest. not in "
"routing table." % (self, packet))
return
dest_link = routing_table[packet.dest.id].link
self.send(packet, dest_link, time)
else:
raise UnhandledPacketType
示例3: handle_timeout
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import warning [as 别名]
def handle_timeout(self, packet, time):
if self.last_drop is None or \
time - self.last_drop > TCPTahoe.TIMEOUT_TOLERANCE:
self.ss = True
self.ssthresh = max(self.host.cwnd / 2, TCPTahoe.INITIAL_CWND)
self.set_window_size(time, TCPTahoe.INITIAL_CWND)
self.last_drop = time
Logger.warning(time, "Timeout Received. SS_Threshold -> %d" % self.ssthresh)
示例4: DataGatherer
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import warning [as 别名]
class DataGatherer(object):
def __init__(self, cfg):
self.cfg = cfg
self.downloader = Downloader(cfg)
self.logger = Logger(cfg)
self.parser = AnotherHTMLParser(self.logger)
self.pairs = set()
self.db_handler = DBHandler(cfg)
self._word_dict = None
def read_raw_pairs(self, delimiter=',', limit=0):
path = cfg['train_path']
try:
f = open(path)
except IOError:
self.logger.critical("Can't open file '{}'!".format(path))
sys.exit()
lines = f.read().split('\n')
pairs = set()
i = 0
for line in lines:
if not line:
continue
if limit and i > limit:
break
i += 1
elements = line.split(delimiter)
try:
if elements[2] == 'left':
pair = (elements[0], elements[1])
else:
pair = (elements[1], elements[0])
if pair in pairs:
self.logger.warning('pair {} is duplicate!'.format(pair))
i -= 1
pairs.add(pair)
except IndexError:
raise AssertionError('line {} is incorrect!'.format(line))
return pairs
def read_pairs(self, delimiter=',', limit=0):
path = cfg['train_fixed_path']
try:
f = open(path)
except IOError:
self.logger.critical("Can't open file '{}'!".format(path))
sys.exit()
lines = f.read().split('\n')
pairs = set()
i = 0
for line in lines:
if not line:
continue
if limit and i > limit:
break
i += 1
elements = line.split(delimiter)
try:
pair = tuple(elements)
if pair in pairs:
self.logger.warning('pair {} is duplicate!'.format(pair))
i -= 1
pairs.add(pair)
except IndexError:
raise AssertionError('line {} is incorrect!'.format(line))
return pairs
def exclude_untracked_videos(self, pairs):
ids = set(self.db_handler.get_all_video_ids())
pairs_set = set(pairs)
for pair in pairs:
for youtube_id in pair:
if youtube_id not in ids:
pairs_set.remove(pair)
break
return pairs_set
def rewrite_pairs(self, pairs):
pairs_fixed = self.exclude_untracked_videos(pairs)
f = open(self.cfg['train_fixed_path'], 'wb')
for pair in pairs_fixed:
f.write(','.join(pair) + '\n')
f.close()
def fill_video_catalog(self, pairs, force=False):
lefts_and_rights = zip(*pairs)
ids = set(lefts_and_rights[0] + lefts_and_rights[1])
if not force:
ids_cache = set(self.db_handler.get_all_video_ids())
ids.difference_update(ids_cache)
for i, youtube_id in enumerate(ids):
if i % 100 == 0:
#.........这里部分代码省略.........
示例5: receive
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import warning [as 别名]
def receive(self, packet, time):
"""
Handles receipt of a packet.
:param packet: Packet received
:type packet: Packet | AckPacket
:param time: Time the packet was received
:type time: int
:return: Nothing
:rtype: None
"""
Logger.info(time, "%s received packet %s." % (self, packet))
# Ack packet, drop stored data that might need retransmission
if isinstance(packet, AckPacket):
flow_id = packet.flow_id
Rn = packet.request_number
if self.current_request_num is None:
self.current_request_num = Rn
else:
self.current_request_num = max(Rn, self.current_request_num)
# Receiving request number Rn means every packet with sequence
# number <= Rn - 1 was received, so those have been acked. No need
# to wait for their ack or to resend.
acked_packets = []
for packet_id, packet_data in self.awaiting_ack.items():
acked_packet, _ = packet_data
if acked_packet.sequence_number < Rn:
acked_packets.append(packet_id)
for acked_packet_id in acked_packets:
acked_packet, sent_time = self.awaiting_ack[acked_packet_id]
if acked_packet in self.queue:
self.queue.remove(acked_packet)
del self.awaiting_ack[acked_packet_id]
self.dispatch(RTTEvent(flow_id, time, time - sent_time))
self.congestion_control.handle_receive(packet, time)
Sn, Sb, Sm = self.sequence_nums
if Rn > Sb:
Sm = Sm + (Rn - Sb)
Sb = Rn
Sn = Sb
self.send_packets(time, flow_id)
self.sequence_nums = (Sn, Sb, Sm)
elif isinstance(packet, RoutingPacket):
return
# Regular packet, send acknowledgment of receipt
elif isinstance(packet, FlowPacket):
if packet.flow_id not in self.request_nums:
self.request_nums[packet.flow_id] = 0
if packet.sequence_number == self.request_nums[packet.flow_id]:
Logger.warning(time, "Packet %d accepted from %s" % (packet.sequence_number, packet.src))
self.request_nums[packet.flow_id] += 1
else:
Logger.info(time, "Incorrect packet received from %s. Expected %d, got %d." % (packet.src, self.request_nums[packet.flow_id], packet.sequence_number))
ack_packet = AckPacket(packet.flow_id, self, packet.src, self.request_nums[packet.flow_id], packet)
self.send(ack_packet, time)
# Ignore routing packets
else:
raise UnhandledPacketType