我正在编写一个代码,从不同的传感器使用树莓皮输入。有什么方法可以让我在不同的控制台窗口中得到输出。在
代码就是这样的。在
def usensor():
distance1=GPIO.input(port1)
print("Distance Left: %s" %distance1)
distance=GPIO.input(port)
print("Distance Right: %s" %distance)
def lsensor():
distance=Linput(); #predefined function
print("Forward Distance: %s" %distance)
def main():
a = threading.Thread(target=usensor)
s = threading.Thread(target=lsensor)
a.start()
s.start()
if __name__ == '__main__':
main()
如何在不同的窗口中显示两个线程的输出,以便更容易阅读?在
如果不进入编程窗口(在Python中非常实用,但可能没有复杂性),我建议您偷偷地使用named pipe。在
假设您创建了一个名为
/tmp/pipe1
的命名管道(通常称为fifo)。您可以让您的程序打开这个FIFO进行输出,并将其中一个输出流写入这个FIFO(研究print
函数的file
参数)。在您只需打开另一个终端窗口,然后运行命令
当程序写入命名管道时,输出应该出现在第二个窗口中。喂!在
相关问题 更多 >
编程相关推荐