diff --git a/import_export_canalblog.py b/import_export_canalblog.py index beb9e3e..6e1e510 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -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) \ No newline at end of file diff --git a/lib/WPExport.py b/lib/WPExport.py index af57a03..b6e7800 100644 --- a/lib/WPExport.py +++ b/lib/WPExport.py @@ -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: