Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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_Multithreading_Apache_Cgi_Subprocess - Fatal编程技术网

Python 线程中的子进程。线程挂起

Python 线程中的子进程。线程挂起,python,multithreading,apache,cgi,subprocess,Python,Multithreading,Apache,Cgi,Subprocess,我不明白为什么下面的代码挂起了。当我从控制台运行它时,一切正常,但当我尝试通过浏览器运行它时,页面挂起。 我正在使用Python 2.7.2 类MyThread(threading.Thread): 定义初始化(自): self.stdout=None self.stderr=None threading.Thread.\uuuu init\uuuu(self,name=“snapshot”,) def运行(自): p=subprocess.Popen([“pwd”],shell=True,st

我不明白为什么下面的代码挂起了。当我从控制台运行它时,一切正常,但当我尝试通过浏览器运行它时,页面挂起。 我正在使用Python 2.7.2

类MyThread(threading.Thread):
定义初始化(自):
self.stdout=None
self.stderr=None
threading.Thread.\uuuu init\uuuu(self,name=“snapshot”,)
def运行(自):
p=subprocess.Popen([“pwd”],shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=None)
p、 沟通
myThread=myThread()
myThread.start()
myThread.join()
更新 我使用Apache作为CGI运行Python。正在运行的系统是Gentoo 2.1


我认为问题出在Apache上。不知何故,它阻塞了新线程,但我不确定。

尝试使用
shell=False运行它

我怀疑当您在web框架中运行此代码时,您并没有真正的shell,这会导致问题

或者,您不能从web服务器进程中重用
stdout
stdin
,而尝试使用
子进程.PIPE执行此操作会导致挂起


我假设您实际上不需要运行
pwd
,您只是将其作为一个示例,但如果您确实需要
pwd
,这是一种不必要的复杂方法。只需将其替换为
os.curdir
属性。

存在语法错误-否:“在类定义之后。通过浏览器运行”是什么意思?如果您使用的是pythonweb框架,那么您应该指定哪个框架,以及您是直接运行它还是在apache/nginx/etc后面运行它。我尝试使用
Shell=False运行
Popen
,但没有成功。我还尝试将一个file对象传递给
stdout
stdin
,但创建该文件时没有使用
pwd
命令的任何输出。