subprocess.Popen()具有无限循环的python文件永远不会调用该文件

时间:2019-03-08 17:45:04

标签: python subprocess

我在Raspberry Pi上有两个.py文件,我试图在其中调用一个文件keep_awake.py,该文件包含:

import time
import serial
while True:
    time.sleep(5)
    for option in ["on", "off"]:
        for board in ["ACM0", "ACM1"]:
            request = serial.Serial(f"/dev/tty{board}", 19200, timeout=1)
            for j in [0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"]:
                request.write(f"relay {option} {j}\r".encode("utf-8"))
            request.close()
        time.sleep(.1)

此代码将通过焊接到电路板上的电线写入继电器到单击按钮。我已经测试了此代码,并且知道它可以工作。但是,当我从这样的父文件中调用它时 subprocess = Popen(["python", "/home/pi/Desktop/DLMW-ART/tools/keep_awake.py"], stdout=PIPE, stderr=STDOUT, universal_newlines=True) 该代码无法运行。

此操作的目的是按下设备按钮,以使其在固件更新过程中保持唤醒状态,然后终止子进程,以免干扰脚本的其余部分。所以我希望父文件看起来像这样:

#Several print statements to let me know where in the script I am
subprocess = Popen(["python", "/home/pi/Desktop/DLMW-ART/tools/keep_awake.py"], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
#Firmware update code will live here
time.sleep(20) #used for testing the call
subprocess.kill()

此代码循环运行,因此我可以清楚地看到主文件中的多个打印语句,但是在子过程中什么也没有发生,并且没有单击设备。我打出subprocess.Popen错误吗?

0 个答案:

没有答案
相关问题