本文整理汇总了Python中Server.Server.put方法的典型用法代码示例。如果您正苦于以下问题:Python Server.put方法的具体用法?Python Server.put怎么用?Python Server.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Server
的用法示例。
在下文中一共展示了Server.put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Simulator
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import put [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
#.........这里部分代码省略.........