Ver Fonte

modify while cycle problem

highroom há 8 anos atrás
pai
commit
e46cba10c0
2 ficheiros alterados com 10 adições e 9 exclusões
  1. 7 6
      Schedule/ProxyCheck.py
  2. 3 3
      Schedule/ProxyValidSchedule.py

+ 7 - 6
Schedule/ProxyCheck.py

@@ -13,7 +13,7 @@
 __author__ = 'J_hao'
 
 import sys
-from time import sleep
+import threading
 from threading import Thread
 
 sys.path.append('../')
@@ -34,7 +34,8 @@ class ProxyCheck(ProxyManager, Thread):
         self.item_dict = item_dict
 
     def run(self):
-        if self.queue.qsize():
+        while self.queue.qsize():
+            print('%s active threads, %s queue size' % (threading.active_count(), self.queue.qsize()))
             proxy = self.queue.get()
             count = self.item_dict[proxy]
             if validUsefulProxy(proxy):
@@ -43,11 +44,11 @@ class ProxyCheck(ProxyManager, Thread):
                     self.db.put(proxy, num=int(count) - 1)
                 else:
                     pass
-                self.log.info('ProxyCheck: {} validation pass'.format(proxy))
+                print('ProxyCheck: {} validation pass'.format(proxy))
             else:
-                self.log.info('ProxyCheck: {} validation fail'.format(proxy))
+                print('ProxyCheck: {} validation fail'.format(proxy))
                 if count and int(count) > FAIL_COUNT:
-                    self.log.info('ProxyCheck: {} fail too many, delete!'.format(proxy))
+                    print('ProxyCheck: {} fail too many, delete!'.format(proxy))
                     self.db.delete(proxy)
                 else:
                     self.db.put(proxy, num=int(count) + 1)
@@ -57,4 +58,4 @@ class ProxyCheck(ProxyManager, Thread):
 if __name__ == '__main__':
     # p = ProxyCheck()
     # p.run()
-    pass
+    pass

+ 3 - 3
Schedule/ProxyValidSchedule.py

@@ -27,7 +27,7 @@ class ProxyValidSchedule(ProxyManager, object):
         ProxyManager.__init__(self)
         self.queue = Queue()
 
-    def __validProxy(self, threads=5):
+    def __validProxy(self, threads=50):
         """
         验证useful_proxy代理
         :param threads: 线程数
@@ -51,7 +51,7 @@ class ProxyValidSchedule(ProxyManager, object):
                 self.__validProxy()
             else:
                 print('Time sleep 5 minutes.')
-                time.sleep(60 * 5)
+                time.sleep(60 * 1)
                 self.put_queue()
 
     def put_queue(self):
@@ -68,4 +68,4 @@ def run():
 
 if __name__ == '__main__':
     p = ProxyValidSchedule()
-    p.main()
+    p.main()