thread 50%

This commit is contained in:
Valentin CZERYBA 2023-04-25 00:34:25 +02:00
parent aaac2385a3
commit 0acd5067cb
2 changed files with 19 additions and 11 deletions

View File

@ -2,14 +2,18 @@
from requests.auth import HTTPBasicAuth
from getpass import getpass
from urllib.parse import urlparse
from concurrent import futures
import argparse, logging, threading
import multiprocessing
from lib.WPImport import WPimport
from lib.WPExport import WPExport
def download(name_thread, max_thread, exportWp, html, img):
exportWp.setName(name_thread)
#def download(args):
webpage = exportWp.getUrlPage(name_thread, max_thread)
if html is False:
exportWp.downloadHTML(webpage)
@ -164,12 +168,15 @@ if __name__ == '__main__':
exportWp.downloadCss()
if args.html is False or args.img is False:
threads = []
for i in range(0, int(args.parallel)):
t1 = multiprocessing.Process(name="Process-{0}".format(i + 1), target=download, args=(i, 3, exportWp,args.html, args.img))
threads.append(t1)
ex = futures.ThreadPoolExecutor(max_workers=int(args.parallel))
#args = [int(args.parallel), exportWp, args.html, args.img]
#f = ex.map(download, args)
#print("wait !!!")
wait_for = [
ex.submit(download, i, int(args.parallel), exportWp, args.html, args.img)
for i in range(0, int(args.parallel))
]
for thread in threads:
thread.start()
thread.join()
#for i in range(0, int(args.parallel)):
# threading.Thread(name="Thread-{0}".format(i + 1), target=download, args=(i, 3, exportWp,args.html, args.img)).start()
exit(0)

View File

@ -11,7 +11,7 @@ class WPExport:
self._logger = logger
self._parser = parser
self._dir = directory
self._name = "Process-0"
self._name = "Thread-0"
self._request = requests.Session()
@ -26,7 +26,7 @@ class WPExport:
# Set name
def setName(self, name):
self._name = "Process-{}".format(int(name) + 1)
self._name = "Thread-{0}".format(int(name) + 1)
# Set URL
@ -62,6 +62,7 @@ class WPExport:
# Get URL
def getUrlPage(self, index_thread, max_thread):
self._name = "Thread-{0}".format(index_thread + 1)
try:
page = self._request.get(self._url)
except Exception as err: