【发布时间】: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.exe 和pythonw.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