python文件运行一段时间后失效,IIS启动的Python进程在一段时间后停止运行

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

解决方案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 will kill off and recycle a process that is sitting idle for too long. That includes any child processes that your IIS process launched.

What you should have done is write your Python process not as something kicked off by the website code but as a Windows Service. The service runs independently of the website code and isn't subject to IIS policies and procedures.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值