I tried the following script but the log does not work.
import time
import concurrent.futures
import logging
import os
######## Logging ################
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
file_handler = logging.FileHandler(os.path.join('logs','pipeline2.log'))
#In case we have also a StreamHandler with level of INFO
file_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
def f(x):
time.sleep(0.001) # to visualize the progress
logger.info(x**2)
def run(f, my_iter):
"""
https://stackoverflow.com/questions/51601756/use-tqdm-with-concurrent-futures
"""
import concurrent.futures
my_iter = list(my_iter)
l = len(my_iter)
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
futures = {executor.submit(f, arg): arg for arg in my_iter}
results = {}
for future in concurrent.futures.as_completed(futures):
arg = futures[future]
results[arg] = future.result()
my_iter = range(10000)
run(f, my_iter)
When running the script: I do not see any file pipeline2.log which appears in the logs. How can I solve this issue?
Edit: as suggested i retrieve tqdm (i do not think it can interfer)n in the code so it could be easyly reproductible.