【问题标题】:Python erroring when called from Apache but not commandline with close failed in file object destructor:从 Apache 调用 Python 时出错,但在文件对象析构函数中关闭时没有关闭命令行时出错:
【发布时间】:2011-11-10 17:18:59
【问题描述】:

我有一个 Python 脚本,它在从命令行调用时可以完美运行,但在从同一台机器上的 Apache 上运行的 php 脚本调用时会死掉。

错误消息(从 Apache 错误日志中抓取):

close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr

在 PHP 中调用:

$exec_string = '/usr/bin/python /path/to/file/doSearch.py "' . $data[ 'term' ] . '"' . $id . ' &';
pclose( popen( $exec_string , 'r' ) );

Python 文件正在处理数据,然后写回文件系统。

【问题讨论】:

    标签: php python apache exec


    【解决方案1】:

    我认为您在第一个参数之后缺少一个空格。试试这个:

    $exec_string = '/usr/bin/python /path/to/file/doSearch.py "' . $data[ 'term' ] . '" ' . $id . ' &';
    //      see hat here -->                                                           ^
    

    您可能希望确保您也转义所有这些数据,以使其对 CLI 安全。

    【讨论】:

      【解决方案2】:

      您的流程中应该有一些输出要在 popen 函数中执行。 但是pclose在直接fclose这个读取文件流的时候会出现这个异常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-06
        • 1970-01-01
        • 1970-01-01
        • 2013-04-01
        • 2016-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多