Python process started by IIS stops running after awhile

B

Bullvay1909

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!

Continue reading...
 
Back
Top Bottom