Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 波本小姐被吊死了_Python - Fatal编程技术网

Python 波本小姐被吊死了

Python 波本小姐被吊死了,python,Python,def hello(): 尽管如此: 打印“subprocess=”+str(os.getpid()) 时间。睡眠(1) def基尔pid(pid): 打印“kill”+str(pid) 操作系统(“taskkill”+'/T/F/pid'+str(pid)) p=subprocess.Popen(hello()) #p=子流程.Popen(“ping 10.193.101.34”,shell=True) 打印“在子流程之后” t=threading.Timer(3.0,killPid,args

def hello():
尽管如此:
打印“subprocess=”+str(os.getpid())
时间。睡眠(1)
def基尔pid(pid):
打印“kill”+str(pid)
操作系统(“taskkill”+'/T/F/pid'+str(pid))
p=subprocess.Popen(hello())
#p=子流程.Popen(“ping 10.193.101.34”,shell=True)
打印“在子流程之后”
t=threading.Timer(3.0,killPid,args=(p.pid,)

t、 start()#3秒钟后,“hello,world”将被打印出来
您希望将函数hello()作为一个进程执行。要做到这一点,你可以试着打电话给Popen,比如

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

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

subprocess.Popen
甚至不执行。很明显,因为“after subprocess”不会在控制台中打印
hello()
永远不会完成,因此永远不会计算
Popen
的输入参数。在调用之前,必须对所有输入参数求值。Popen用于运行外部二进制文件。您似乎希望以非阻塞方式运行python代码。您正在寻找吗?我想使用popen将函数hello()作为进程来执行。它可以在python的一个实例中使用popen将函数hello()作为进程来执行吗?您可能无法执行此操作,因为popen用于创建子进程