本文整理汇总了Python中Server.Server.pop方法的典型用法代码示例。如果您正苦于以下问题:Python Server.pop方法的具体用法?Python Server.pop怎么用?Python Server.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Server
的用法示例。
在下文中一共展示了Server.pop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import pop [as 别名]
def main():
print "Running FTQueueTest..."
label = 5
item = 10
s = Server()
# Test the queue creation
qid = s.create_Queue(label)
assertion(isinstance(qid, int), "Create queue returned a int as a queue id.")
# Test that the right label returns the right queue id
assertion(s.get_qid(label) == qid, "Label return the right qid.")
# Test that the queue is the right size
s.push(qid, item)
assertion(s.qsize(qid) == 1, "Queue is the right size.")
# Test that the queue retrieves the items in the right order
s.push(qid, 11)
assertion(s.pop(qid) == item, "Queue pop returns the right item.")
assertion(s.top(qid) == 11, "Queue top returns the right item.")
assertion(s.qsize(qid) == 1, "Queue should not be empty.")
示例2: Simulator
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import pop [as 别名]
class Simulator(object):
def __init__(self,
stats = None,
render = None) :
self.waiting = PriorityQueue()
self.server = Server()
self.active = None
self.events = EventList()
self.clock = 0
self.tasks = []
self.until = 0
# Statistics
if stats is not None:
self.stats = True
self.stats_file = open(stats, "wb")
self.stats_writer = csv.writer(self.stats_file, delimiter='|', lineterminator='\n')
self.write_headers()
else:
self.stats = False
# Rendering
if render is not None:
self.render = True
self.render_file = render
self.render_data = dict()
else:
self.render = False
def update(self):
"""
Update simulator state after any event.
"""
# Which instance to execute ?
self.selectInstance()
# If there is no instance, nothing to do
if self.active is None:
return
else:
# Compute finish event
self.events.put(self.active.event(self.clock))
# Compute server event
self.events.put(self.server.event(self.clock))
def advance(self, time):
"""
Advance the simulator to the given time.
"""
if self.active is not None:
self.active.advance(self.clock, time)
self.server.advance(self.clock, time)
self.clock = time
def selectInstance(self):
"""
Select (set the variables) the instance to execute on the simulator
according to the state of various entities.
"""
if self.server.state != Server.WAITING:
if self.waiting.isEmpty():
self.active = None
else:
self.active = self.waiting.first()
elif self.waiting.isEmpty():
self.active = self.server.activate()
else:
if self.waiting.first().priority > self.server.priority:
self.active = self.waiting.first()
else:
self.active = self.server.activate()
def reactArrival(self, event):
# Put the new instance on its waiting list
if event.instance.type == Instance.SOFT:
self.server.put(event.instance)
elif event.instance.type == Instance.HARD:
self.waiting.put(event.instance, event.instance.priority)
# Compute the next arrival
self.events.put(event.instance.task.nextArrival(event.time))
def reactFinish(self, event):
# Remove the instance from its waiting list
if event.instance.type == Instance.SOFT:
self.server.pop()
elif event.instance.type == Instance.HARD:
self.waiting.pop()
# Compute statistics
if self.stats :
event.instance.statistics()
self.write_instance(event.instance)
# Compute rendering
if self.render :
task = event.instance.task
#.........这里部分代码省略.........