From d3a03e1cb3d9fb34c7e2fc2e3a499b145b574ca5 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 29 May 2023 23:36:11 +0200 Subject: [PATCH] add wait --- import_export_canalblog.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/import_export_canalblog.py b/import_export_canalblog.py index 4fb77b3..1e83ab9 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -3,7 +3,7 @@ from requests.auth import HTTPBasicAuth from getpass import getpass from urllib.parse import urlparse from concurrent import futures -from concurrent.futures import as_completed, wait +from concurrent.futures import as_completed, wait, ALL_COMPLETED import argparse, logging, threading from lib.WPImport import WPimport @@ -221,9 +221,10 @@ if __name__ == '__main__': importWp.setUrl(i) importWp.fromFile(files=args.file.split(",")) if len(args.directory) > 0: - remove(args, basic, logger, ssl_wordpress) try: with futures.ThreadPoolExecutor(max_workers=int(args.parallel)) as ex: + wait_for = [ ex.submit(remove, i, args.parallel, args, basic, logger, ssl_wordpress) for i in range(0, int(args.parallel)) ] + wait(wait_for, return_when=ALL_COMPLETED) wait_for = [ ex.submit(importDirectory, i, int(args.parallel), args.directory, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress) for i in range(0, int(args.parallel)) @@ -231,13 +232,16 @@ if __name__ == '__main__': except Exception as err: logger.error("Threading error : {0}".format(err)) if len(args.canalblog) > 0: - remove(args, basic, logger, ssl_wordpress) try: with futures.ThreadPoolExecutor(max_workers=int(args.parallel)) as ex: + wait_for = [ ex.submit(remove, i, args.parallel, args, basic, logger, ssl_wordpress) for i in range(0, int(args.parallel)) ] + wait(wait_for, return_when=ALL_COMPLETED) wait_for = [ ex.submit(importUrl, i, int(args.parallel), args.canalblog, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, ssl_canalblog) for i in range(0, int(args.parallel)) ] + + except Exception as err: logger.error("Threading error : {0}".format(err)) exit(0)