我要编写一个脚本,控制浏览器,如果当前已经运行了超过两秒钟就关闭,但是在执行的过程中执行到print函数时就会发生IOError: [Errno 0] Error的错误,代码和错误如下图
代码单独粘出来
#coding:utf-8
from pydbg import *
import os
import copy
import time
def check_timeout():#防止非加载时timeout
dbg1 = pydbg()
now_status = []
while(True):
print("------------------------------------------")
last_status = copy.deepcopy(now_status)
print("last status:" + str(last_status))
now_status = []
for (pid,name) in dbg1.enumerate_processes():
if(name == "firefox.exe"):
now_status.append(pid)
time.sleep(2)
print("now status:" + str(now_status))
if(now_status==last_status):
if(now_status ==[]):
print("now_status enpty")
else:
print("last is the same as now ,kill firefox")
os.popen("taskkill /PID firefox.exe /f")
else:
print("last status is different from now status")
def main():
check_timeout()
if __name__ == '__main__':
main()
请表哥们帮帮忙!!