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


Python Proxy.start方法代码示例

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


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

示例1: Robosapien

# 需要导入模块: from proxy import Proxy [as 别名]
# 或者: from proxy.Proxy import start [as 别名]

#.........这里部分代码省略.........

    def ping(self):
        return

    '''
    Drives the robot forward a certain distance.
    '''

    def travel(self, command):
        print(command)
        if len(command) >= 3:
            command = command.strip("t\n")
            distance = float(command)

            if distance > 0:
                message_time = time.time()

                interrupted = False

                if distance < DISTANCE_PER_STEP:
                    number_of_steps = 1
                else:
                    number_of_steps = distance / DISTANCE_PER_STEP

                steps_taken = 0

                self.invoke_lirc(FORWARD_STEP)
                step_time = time.time()

                # Will just have to wait for some predefined time
                # or check the accelerometer. Drift will happen!
                while True:
                    # Check for any commands that could cancel this.
                    with self.proxy.command_mutex:
                        if len(self.proxy.command_queue) > 0:
                            interrupted = True
                            break

                    # Either wait for a predefined time to elapse
                    # or probe the accelerometer for movement.
                    if time.time() - step_time >= TIME_PER_STEP:
                        steps_taken += 1

                        if steps_taken < number_of_steps:
                            self.invoke_lirc(FORWARD_STEP)
                            step_time = time.time()
                        else:
                            break

                    if time.time() - message_time >= MESSAGE_RATE:
                        self.update_odometry(steps_taken)
                        self.send_odometry()
                        message_time = time.time()

                # Compute new odometry based on the number steps that were taken.
                self.update_odometry(steps_taken)

                self.invoke_lirc(STOP)
                self.proxy.send("travelled: %.2f" % (steps_taken / DISTANCE_PER_STEP) + "\n")

                if interrupted:
                    print("interrupted during travel!")
                    with self.proxy.command_mutex:
                        self.process_command(self.proxy.command_queue.pop())

    '''

    '''

    def run(self):
        self.proxy.start()

        message_time = time.time()

        while True:
            try:
                command = ""

                # Check the command poll.
                with self.proxy.command_mutex:
                    if len(self.proxy.command_queue) > 0:
                        command = self.proxy.command_queue.pop()

                # If it exists then process it.
                if COMMANDS.count(command[0]) < 1:
                    self.process_command(command)

                if time.time() - message_time >= MESSAGE_RATE:
                    self.send_odometry()
                    message_time = time.time()
            except Exception as err:
                print(str(err))
                break

        self.proxy.socket.close()

        print("Cleaning up GPIO!")
        io.cleanup()

        print("Exiting Now!")
开发者ID:swordmaster2k,项目名称:botnav,代码行数:104,代码来源:robosapien.py

示例2: run

# 需要导入模块: from proxy import Proxy [as 别名]
# 或者: from proxy.Proxy import start [as 别名]
        def run(self):
		p = Proxy(logger)
		p.start()
开发者ID:delqn,项目名称:python-http-proxy,代码行数:5,代码来源:start_proxy.py


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