【问题标题】:Python process started by IIS stops running after awhile由 IIS 启动的 Python 进程在一段时间后停止运行
【发布时间】:2019-02-01 03:51:51
【问题描述】:

我写了一个python 脚本,它从给定的网页收集链接。您可以在下面找到代码 sn-p。 (但我认为这不是编码问题)。

当我在命令行(具有管理员权限)中执行脚本时,一切都按预期工作,但是当我从 PHP 运行脚本时,它会在大约 30 分钟后停止运行,没有任何异常。对我来说,Windows Server 2016 似乎在一段时间后杀死了 python 进程(进程由没有管理员权限的 IIS 用户启动)。

知道如何告诉 Windows/IIS 不要杀死 python 进程吗?

这就是我从PHP 调用脚本的方式:

$command = 'C:\\Python36\\python.exe C:\\Scripts\\myscript.py ';
pclose(popen("start /B ".$command, "w"));

我尝试了python.exepythonw.exe。脚本正常启动,但大约 30 分钟后停止。

def getAllLinksOnCurrentPage():
elems = driver.find_elements_by_xpath("//a[@href]")
for elem in elems:
    f = elem.get_attribute("href")
    if testurl in f:
        if f not in linkcollector:
            linkcollector.append(f)


try:
    driver.get(testurl)

    for currentpage in linkcollector:
        driver.get(currentpage)
        getAllLinksOnCurrentPage()


    #Write all URLs to Logfile
    with open('C:\Scripts\Logfiles\\Logfile.txt', "a") as file:
        for currentpage in linkcollector:
            file.write("\n%s" %currentpage)

except Exception as e:
    #Catch Unknown Exception
    with open('C:\Scripts\Logfiles\\'+str(testrun)+'_Logfile.txt', "a") as file:
        file.write("\n Unknown Exception: " %str(e))

感谢每一个输入,谢谢!

【问题讨论】:

  • 你找到解决办法了吗?

标签: php python iis-8 windows-server-2016


【解决方案1】:

自己找到的解决方案:

IIS -> 选择服务器 -> 默认应用程序池 -> 高级设置 -> 设置 0 为“空闲超时”和“常规时间间隔”

【讨论】:

  • 即使将池设置为始终运行模式并将网站设置为启用预加载,这也不起作用。大约 5 分钟后,如果没有请求,python 进程就会终止。
【解决方案2】:

这可能与max-execution-time 有关 - 脚本在终止之前允许运行的最长时间(以秒为单位)。

您可以通过编辑 php.ini 或调用 set-time-limit 来更改此属性

【讨论】:

  • 新版本的 PHP 不支持最大执行时间
猜你喜欢
  • 2018-08-06
  • 1970-01-01
  • 1970-01-01
  • 2013-12-21
  • 1970-01-01
  • 1970-01-01
  • 2011-05-18
  • 2015-12-29
  • 1970-01-01
相关资源
最近更新 更多