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


Python Driver.destroy方法代码示例

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


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

示例1: Car

# 需要导入模块: from driver import Driver [as 别名]
# 或者: from driver.Driver import destroy [as 别名]

#.........这里部分代码省略.........
            - drives car
            - processes Collision objects and decides course of action
            - constructs messages to other cars
        """

        while not self._kill:
            collisions_to_delete = set()
            for car_name, collision in self._collisions.iteritems():
                # TODO might need this not to block so we can keep moving
                collision.lock.acquire()

                if collision.critical:
                    # stop driver, send ROW
                    self._driver.stop()
                    self.state = CarState.STOPPED
                    collision.critical = False

                if collision.state == CollisionState.SENT_MESSAGE:
                    pass # wait for reply

                elif collision.state == CollisionState.WAITING:
                    self._driver.stop() # repeated calls are benign
                    self.state = CarState.STOPPED

                    if collision.safe_to_drive(self.frames[-1][car_name]):
                        print "SAFE TO PROCEED"
                        collision.state = CollisionState.RESOLVED

                elif collision.state == CollisionState.RESOLVED:
                    print "RESOLVED: going..."
                    self._driver.go() # repated calls are benign
                    self._state = CarState.DRIVING
                    collisions_to_delete.add(car_name)

                elif collision.state == CollisionState.NEW:
                    # send ROW
                    priority = Car._generate_priority()
                    self._talker.send_message(Message(Message.ROW, self.name, collision.car_name,
                        collision.location, collision.frame_num, priority_val=priority))
                    collision.state = CollisionState.SENT_MESSAGE
                    collision.priority_val = priority
                    print "ROW SENT"

                elif collision.state == CollisionState.RECEIVED_MESSAGE:
                    assert collision.message != None
                    # process collision message
                    print "RECEIVED MESSAGE NORMAL"

                    if collision.message.type == Message.ROW:
                        val = Car._generate_priority()
                        if collision.message.priority_val > val:
                            # send GO, wait
                            self._talker.send_message(Message(Message.GO, self.name, collision.message.other_name,
                                                        collision.location, collision.frame_num))
                            collision.state = CollisionState.WAITING
                            print "WAIT"

                        else:
                            # send WAIT
                            self._talker.send_message(Message(Message.STAY, self.name, collision.message.other_name,
                                                                collision.location, collision.frame_num))
                            collision.state = CollisionState.RESOLVED
                            print "RESOLVED... GO"

                    elif collision.message == Message.GO:
                        collision.state = CollisionState.RESOLVED
                    else:
                        collision.state = CollisionState.WAITING

                    collision.message = None

                collision.lock.release()

            for key in collisions_to_delete:
                del self._collisions[key]
                print "DELETED COLLISION", key

            time.sleep(utils.THREAD_SLEEP)

    @staticmethod
    def _generate_priority():
        return random.randint(0, utils.PRIORITY_CEILING)

    def start(self):
        self._vicon_client.start()
        self._talker.start()
        self._collision_worker.start()
        self._message_worker.start()
        self._main_worker.start()

    def stop(self):
        self._kill = True
        self._driver.stop()
        self._driver.destroy()
        self._vicon_client.stop()
        self._talker.stop()
        self._collision_worker.join()
        self._message_worker.join()
        self._main_worker.join()
        return True
开发者ID:jlucier,项目名称:6.S062-car-swarm,代码行数:104,代码来源:car.py


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