Jason 1 年間 前
コミット
69b4d96180
3 ファイル変更62 行追加59 行削除
  1. 15 12
      website_clickjobs/gen_seo2a.py
  2. 24 24
      website_clickjobs/type-V/c2.py
  3. 23 23
      website_clickjobs/type-V/c2S.py

+ 15 - 12
website_clickjobs/gen_seo2a.py

@@ -24,7 +24,7 @@ import time
 import requests
 import pymysql
 import urllib.parse
-import concurrent.futures
+import multiprocessing
 pymysql.install_as_MySQLdb()
 from userAgentRandomizer import userAgents
 driver=None
@@ -265,14 +265,17 @@ def exe():
         db.close()
         time.sleep(20)
 
-runcount=1
-while True:
-    print("Run "+ str(runcount))
-    with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
-        future = executor.submit(exe)
-        try:
-            result = future.result(timeout=120)
-            print("Function completed")
-            runcount+=1
-        except concurrent.futures.TimeoutError:
-            print("Function execution timed out")
+if __name__ == '__main__':
+    runcount=1
+    while True:
+        print("Run "+ str(runcount))
+        start_time = time.time()
+        p = multiprocessing.Process(target=exe)
+        p.start()
+        p.join(120)
+        if p.is_alive():
+            print("Overtime")
+            p.kill()
+        p.join()
+        duration = time.time()-start_time
+        print("Runs: " + str(runcount) + " | Duration: " + str(duration))

+ 24 - 24
website_clickjobs/type-V/c2.py

@@ -1,6 +1,6 @@
 #coding=utf-8
 from _execute import *
-import concurrent.futures
+import multiprocessing
 
 clickvideo = 2 # set to 1 to alert if video is found (DOES NOT CLICK!), requires whitelist
 # ^ set to 2 to click the video when found, requires whitelist
@@ -18,33 +18,33 @@ def addvids(target):
     return target
 
 def exe():
-    start_time = time.time()
     target=[]
     kw = pickterm(client)
     target = addvids(target)
     print(len(target))
     process_one(kw, target, clickvideo, savefile, sec)
-    duration = time.time()-start_time
-    print("Runs: " + str(runcount) + " | Duration: " + str(duration))
 
-if clickvideo == 1 or clickvideo == 2:
-    runcount=0
-    kws=None
-    while True:
-        try:
-            runcount+=1
-            with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
-                future = executor.submit(exe)
-                try:
-                    result = future.result(timeout=120)
-                    print("Function completed")
-                except concurrent.futures.TimeoutError:
-                    print("Function execution timed out")
-                    future.cancel()
-        except:
-            print('Runtime Error')
-            traceback.print_exc()
-        time.sleep(7)
+if __name__ == '__main__':
+    if clickvideo == 1 or clickvideo == 2:
+        runcount=0
+        kws=None
+        while True:
+            try:
+                runcount+=1
+                start_time = time.time()
+                p = multiprocessing.Process(target=exe)
+                p.start()
+                p.join(120)
+                if p.is_alive():
+                    print("Overtime")
+                    p.kill()
+                p.join()
+                duration = time.time()-start_time
+                print("Runs: " + str(runcount) + " | Duration: " + str(duration))
+            except:
+                print('Runtime Error')
+                traceback.print_exc()
+            time.sleep(7)
 
-elif savefile == 1:
-    execute(termlist, "", clickvideo, savefile, sec)
+    elif savefile == 1:
+        execute(termlist, "", clickvideo, savefile, sec)

+ 23 - 23
website_clickjobs/type-V/c2S.py

@@ -1,6 +1,6 @@
 #coding=utf-8
 from _execute import *
-import concurrent.futures
+import multiprocessing
 
 clickvideo = 2 # set to 1 to alert if video is found (DOES NOT CLICK!), requires whitelist
 # ^ set to 2 to click the video when found, requires whitelist
@@ -18,32 +18,32 @@ def addvids(target):
     return target
 
 def exe():
-    start_time = time.time()
     target=[]
     kw = pickterm(client)
     target = addvids(target)
     print(len(target))
     process_one(kw, target, clickvideo, savefile, sec)
-    duration = time.time()-start_time
-    print("Runs: " + str(runcount) + " | Duration: " + str(duration))
 
-if clickvideo == 1 or clickvideo == 2:
-    runcount=0
-    kws=None
-    try:
-        runcount+=1
-        with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
-            future = executor.submit(exe)
-            try:
-                result = future.result(timeout=120)
-                print("Function completed")
-            except concurrent.futures.TimeoutError:
-                print("Function execution timed out")
-                future.cancel()
-    except:
-        print('Runtime Error')
-        traceback.print_exc()
-    time.sleep(7)
+if __name__ == '__main__':
+    if clickvideo == 1 or clickvideo == 2:
+        runcount=0
+        kws=None
+        try:
+            runcount+=1
+            start_time = time.time()
+            p = multiprocessing.Process(target=exe)
+            p.start()
+            p.join(120)
+            if p.is_alive():
+                print("Overtime")
+                p.kill()
+            p.join()
+            duration = time.time()-start_time
+            print("Runs: " + str(runcount) + " | Duration: " + str(duration))
+        except:
+            print('Runtime Error')
+            traceback.print_exc()
+        time.sleep(7)
 
-elif savefile == 1:
-    execute(termlist, "", clickvideo, savefile, sec)
+    elif savefile == 1:
+        execute(termlist, "", clickvideo, savefile, sec)