使用apach部署web应用后,Popen出现意外行为

2024-04-25 11:55:57 发布

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

我有一些代码使用子进程来查看git目录中的日志。在本地django开发环境中执行时,我的代码似乎可以正常工作。然而,一旦部署(使用Apache/mode\wsgi),stdout read()的输出将返回空值。我的开发和生产机器现在是一样的,我还试着确保每个文件都是可读的。在

有人知道为什么Popen在这里部署后不返回任何输出吗?谢谢。在

def getGitLogs(projectName, searchTerm=None, since):
    os.chdir(os.path.join(settings.SCM_GIT, projectName))
    cmd = "git log --since {0} -p".format(since)
    p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
    output = p.stdout.read()
    ### here output comes back as expected in dev environment, but empty in once deployed
    return filterCommits(parseCommits(output), searchTerm)

Tags: 代码gitcmdtruereadoutputos部署