问题描述
您好,感谢阅读!
我写了一个Python脚本,它收集来自给定网页的链接。您可以在下面找到代码段。 (但我认为这不是编码问题)
当我在命令行中执行脚本(具有管理员权限)时,一切都按预期工作,但是当我运行来自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])
元素中的元素
:
f = elem.get_attribute(href)
如果f中的testur:
如果f不在linkcollector中:
linkcollector.append(f)
试试:
driver.get(testurl)
for currentpage i n linkcollector:
driver.get(当前页面)
getAllLinksOnCurrentPage()
#将所有URL写入Logfile
with open('C:\Scripts\Logfiles\\Logfile.txt',a)作为文件:
$ b linkcollector中当前页面的$ b:
file.write(\ n%s%currentpage)
除了例外e:
#Catch未知异常
打开('C:\Scripts\Logfiles\\'+ str(testrun)+'_ Logfile.txt', a)作为文件:
file.write(\ n未知异常:%str(e))
每次输入非常感谢,谢谢!
我的尝试:
- python.exe - >属性 - >以管理员身份运行
Hi there, thanks for reading!
I wrote a Python script which is collecting links from a given web page. You can find a code snippet below. (but I think it is not a coding issue)
When I execute the script in command line (with Administrator rights) everything works as expected, but when I run the script from PHP it just stops running after ~30 minutes without any Exception. For me it looks like, that Windows Server 2016 is killing the python process after a certain time. (process is started by IIS User without admin rights)
***Any ideas how to tell Windows/IIS not to kill the python process?***
This is how I call the script from PHP:
$command = 'C:\\Python36\\python.exe C:\\Scripts\\myscript.py ';
pclose(popen("start /B ".$command, "w"));
I tried both python.exe and pythonw.exe
The script is starting normally, but stops after about 30 minutes.
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))
Every input is appreciated, thanks!
What I have tried:
- python.exe -> Properties -> Run as Administrator
推荐答案
这篇关于IIS启动的Python进程在一段时间后停止运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!