Hello,
I have some problems to understand the threading module and the few bits of code I found does not say more.
Here is my simple code of departure (it recursive html pages and sending a message if everything is ok):
It works but will cause speed problems (depending on the number of pages, or pages that are blocked: timeout ...). In short I paralleled the "execute" to use the threading module.
- #! / usr / bin / env python2.6
- # -*- Coding: utf-8 -*-
- import thread
- import urllib2
- class robot:
- def __init__ (self, url):
- url = self.__url
- def queue (self):
- for page in self.__url:
- html = self.execute (page)
- if html:
- self.sendmail (the content is ok)
- else:
- print "error on page (0)." format (page)
- def execute (self, url):
- "" "
- recursive html content ...
- "" "
- urllib2.url open return (url). read ()
- def sendmail (self, message):
- "" "
- sending a mail ...
- "" "
- pass
- if __name__ == '__main__':
- url = [ "http://google.com", "http://www.techarena.in"]
- recursive = robot (url)
- recursive.queue ()
The worry is that I need to recover the results of this function to generate tests / messages and I do not see how ...
thank you to those who could enlighten me
Bookmarks