当前位置: 首页>>代码示例>>Python>>正文


Python Server.activate方法代码示例

本文整理汇总了Python中Server.Server.activate方法的典型用法代码示例。如果您正苦于以下问题:Python Server.activate方法的具体用法?Python Server.activate怎么用?Python Server.activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server.Server的用法示例。


在下文中一共展示了Server.activate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: activate

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import activate [as 别名]
    def activate(self):
        """install callbacks"""

        Server.activate(self)
        self._selector.notifyOnReadReady(self._socket, self._onConnection)
        self._selector.notifyWhenIdle(self._onSelectorIdle)
开发者ID:haojianggod,项目名称:jd_etl_task,代码行数:8,代码来源:XMLRPCServer.py

示例2: Simulator

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import activate [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
#.........这里部分代码省略.........
开发者ID:markusian,项目名称:hybrid-scheduling,代码行数:103,代码来源:Simulator.py


注:本文中的Server.Server.activate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。