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


Python Scheduler.getNext方法代码示例

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


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

示例1: CPU

# 需要导入模块: from Scheduler import Scheduler [as 别名]
# 或者: from Scheduler.Scheduler import getNext [as 别名]

#.........这里部分代码省略.........
        speed = 1
        
        curr_time = 0
        run = True
        
        started = False
        
        while run:
            # Recibir comandos desde la consola
            while self.conn.poll():
                cc, args = self.conn.recv()
                new_process = None
                
                if cc == self.CC_EXIT:
                    run = False
                    break
                elif cc == self.CC_MAKE_CALL:
                    new_process = CallProcess(self.pid_count + 1, 1, 'make_call', *args)
                elif cc == self.CC_RECEIVE_CALL:
                    new_process = CallProcess(self.pid_count + 1, 2, 'receive_call', *args)
                elif cc == self.CC_SEND_MSG:
                    new_process = MessageProcess(self.pid_count + 1, 3, 'send_msg', *args)
                elif cc == self.CC_RECEIVE_MSG:
                    new_process = MessageProcess(self.pid_count + 1, 4, 'receive_msg', *args)
                elif cc == self.CC_ADD_CONTACT:
                    new_process = AddContactProcess(self.pid_count + 1, 5, 'add_contact', *args)
                elif cc == self.CC_RANDOM:
                    new_process = RandomProcess(self.pid_count + 1, 6, 'random_process', *args)
                elif cc == self.CC_SEND_LOCATION:
                    new_process = SendLocationProcess(self.pid_count + 1, 7, 'send_location', *args)
                elif cc == self.CC_WATCH_LOCATION:
                    new_process = WatchLocationProcess(self.pid_count + 1, 8, 'watch_location', *args)
                elif cc == self.CC_PLAY_GAME:
                    new_process = PlayGameProcess(self.pid_count + 1, 9, 'play_game', *args)
                elif cc == self.CC_PLAY_MUSIC:
                    new_process = PlayMusicProcess(self.pid_count + 1, 10, 'play_music', *args)
                elif cc == self.CC_START_PROCESS:
                    new_process = Process(self.pid_count + 1, 6 , *args)
                elif cc == self.CC_TOP:
                    self.scheduler.top(self.current_process)
                elif cc == self.CC_CALL_HISTORY:
                    Memory.readCallHistory()
                elif cc == self.CC_MSG_HISTORY:
                    Memory.readMsgHistory()
                elif cc == self.CC_SIMULATE:
                    started = True
                    speed = float(args[0]) if len(args) == 1 else 1
                    print 'Empezando simulacion'

                # Se agregan procesos a New
                if new_process is not None:
                    self.pid_count += 1
                    new_queue.put((new_process.start_time, new_process))

            if started:
                # Se agregan procesos de la cola New a la Cola Ready
                i = 0
                n = new_queue.qsize()
                while i < n:
                    process = new_queue.get()[1]
                    if (process.start_time*1000 == curr_time):
                        print 'Agendando Proceso %s numero %s en el tiempo %s' % (process.name,process.pid, curr_time)
                        self.scheduler.add(process)
                    else:
                        new_queue.put((process.start_time, process))
                    i+=1

                if self.current_process is not None:
                    if self.current_process.pending_time <= 0:
                        # Liberar perifericos bloqueados
                        self.current_process.free_peripherals()
                        # Eliminar el proceso del scheduler
                        self.scheduler.dispose(self.current_process)
                        self.current_process = None

                    # El scheduler devuelve el proceso que debe estar actualmente
                    # Si es tiempo de cambiar el proceso y ya hay uno usandose, se cambia
                    elif self.count == self.QUANTUM:
                        self.count = 0
                        #El proceso retirado va al final de la fila
                        self.scheduler.dispose(self.current_process)
                        self.scheduler.add(self.current_process)
                        self.current_process = self.scheduler.getNext()

                # Si la CPU no fue usada anteriormente, vemos si hay otro proceso esperando
                if self.current_process is None:
                    self.current_process = self.scheduler.getNext()

                # Si no, solo aumenta e contador de tiempo
                if self.count == self.QUANTUM:
                    self.count = 0

                if self.current_process is not None:
                    # ejecutar el proceso por la cantidad de tiempo concedida
                    self.current_process.run(self.TIME_STEP, curr_time)

                self.count +=1
                curr_time += self.TIME_STEP
                
            time.sleep(self.TIME_STEP / (1000 * speed))
开发者ID:mtarias,项目名称:soyredes,代码行数:104,代码来源:CPU.py


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