子进程Popen卡住了

2024-10-01 15:31:00 发布

您现在位置:Python中文网/ 问答频道 /正文

def hello(): while True: print 'subprocess = ' + str(os.getpid()) time.sleep(1) def killPid(pid): print 'kill ' + str(pid) os.system("taskkill" + ' /T /F /pid '+ str(pid)) p = subprocess.Popen(hello()) # p = subprocess.Popen("ping 10.193.101.34", shell=True) print 'after subprocess' t = threading.Timer(3.0, killPid, args=(p.pid,)) t.start() # after 3 seconds, "hello, world" will be printed

当人民被吊死的时候? 子进程未被杀死


Tags: truehellotimeosdefsleeppidsubprocess
1条回答
网友
1楼 · 发布于 2024-10-01 15:31:00

它表明您希望将函数hello()作为一个进程来执行。要做到这一点,你可以试着打电话给波本类似的东西

["python","-m",__file__,"-c","hello()"] 

运行执行hello函数的python解释器的新实例

相关问题 更多 >

    热门问题