Originally Posted by
Bachstelze
That's how I would do it, then, what makes you think it memory leaks?
Because memory consumption keeps going up
Then it must be my check() function that memory leaks..
Okay this is how it looks:
PHP Code:
import urllib
import re
import time
hosts = [
'www.google.com',
'www.Fail22222.com' # Fails
]
def Check(hosts):
for hosts in hosts:
try:
f = urllib.urlopen("http://"+hosts).read()
find = re.findall("word" ,f)
find2 = re.findall("DOCTYPE" ,f)
print hosts
try:
if find[0] == "word":
print "Found word"
genPHPuP(hosts)
except IndexError:
try:
if find2[0] == "DOCTYPE":
print "Found DOCTYPE"
genPHPuP(hosts)
except IndexError:
print "Page does not contain DOCTYPE or word"
genPHPwarn(hosts)
except IOError:
print hosts
print "Page does not contain DOCTYPE or word! Server is down!"
genPHPdown(hosts)
def genPHPuP(hosts):
try:
filename = hosts+".php"
print "PHPuP: Writing file: %s" % filename
file = open(filename, 'w')
file.write("<img src=pics/greenV.jpg>" )
file.close()
except IOError:
print "PHPup: Couldn't write to file %s" % filename
def genPHPdown(hosts):
try:
filename = hosts+".php"
print "PHPdown: Writing file: %s" % filename
file = open(filename, 'w')
file.write("<img src=pics/redX.png>" )
file.close()
except IOError:
print "PHPdown: Couldn't write to file %s" % filename
def genPHPwarn(hosts):
try:
filename = hosts+".php"
print "PHPWarn: Writing file: %s" % filename
file = open(filename, 'w')
file.write("<img src=pics/warn.png>" )
file.close()
except IOError:
print "PHPWarn: Couldn't write to file %s" % filename
# Starts Check() every 60 sec
def start():
while True:
Check(hosts)
time.sleep(60)
start()
What I am trying to do is to go through the lists of hosts, check them for 2 different words, and write to a file if it finds the word, does not find the word or if the server is down.
Can you spot any leaks in that? I'm still learning Python.
Thanks a lot!
Bookmarks