Windows 10出现间歇性python cgi错误

Windows 10出现间歇性python cgi错误,python,apache,windows-10,Python,Apache,Windows 10,刚刚将一台PC升级到Windows 10,在Apache下以cgi的形式运行Python脚本时出现了一个奇怪的间歇性错误。特定脚本通过调用help(“modules”)显示可用Python模块的列表。有时脚本执行得很好,但有时会失败。当它失败时,浏览器显示“InternalServerError”,Apache错误日志会显示相对不具信息性的错误消息“在头之前结束脚本输出” 实验表明,每20次尝试中大约有5次出现错误 奇怪的是,当同一台PC使用Windows7时,脚本总是执行得很好,而当在Ubun

刚刚将一台PC升级到Windows 10,在Apache下以cgi的形式运行Python脚本时出现了一个奇怪的间歇性错误。特定脚本通过调用
help(“modules”)
显示可用Python模块的列表。有时脚本执行得很好,但有时会失败。当它失败时,浏览器显示“InternalServerError”,Apache错误日志会显示相对不具信息性的错误消息“在头之前结束脚本输出”

实验表明,每20次尝试中大约有5次出现错误

奇怪的是,当同一台PC使用Windows7时,脚本总是执行得很好,而当在Ubuntu服务器上运行时,同一个脚本(与Apache下的cgi一样)执行得很好。直接作为Python脚本运行(无cgi/Apache)时,即使在Windows 10下也可以正常工作。这个问题只在Windows 10和Apache中出现过

名为testX.py的完整脚本是:

#!/usr/bin/python
# Note the path to Python may vary
#  
print "Content-type: text/html\n"
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
print "<HTML>"
print "<HEAD>"
print "<TITLE>Python Test</TITLE>"
print "</HEAD>"
print "<H1>Python Test Script - Available Modules</H1>"
print "<P><PRE>"
help("modules")
print "</PRE></P>"
print "</HTML>"

现在一切似乎都很好。

如果从命令行运行
help(“模块”)
会发生什么?从Python命令行调用
help(“模块”)
就可以了。
def help_modules():
    from pkgutil import iter_modules
    mod_list = []
    for thismod in iter_modules():
        mod_list.append(thismod[1])
    mod_list.sort()
    nummods = len(mod_list)
    numcols = 6
    numblanks = (-nummods) % numcols
    mod_list.extend([''] * numblanks)
    numrows = len(mod_list) / numcols
    print "<TABLE style='width:100%; table-layout: fixed;'>"
    for i in range(0,numrows):
         print "<TR>"
         for j in range(0,numcols):
             print "<TD>%s" % (mod_list[i+j*numrows])
         print "</TR>"
    print "</TABLE>"    
    return