popen被阻塞
高洛峰
高洛峰 2016-11-04 10:07:06
0
1
936
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

为啥subprogress没被kill?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all (1)
三叔

popen用法错了,它的第一个参数是字符串或者字符串数组,如popen('cat /tmp/log')或者popen(['cat', '/tmp/log'])。

你的代码里在popen中直接调用hello,直接死循环,并没有开启新的进程。


    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!