Good day. I need advice, as one thread, to take data from another while it is being executed. (A bit clumsily, I did not invent a better wording.)
While it looks like this:
import sys import threading import time #Тут можно не смотреть, готовая рабочая функция!!! # Print iterations progress def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█'): """ Call in a loop to create terminal progress bar @params: iteration - Required : current iteration (Int) total - Required : total iterations (Int) prefix - Optional : prefix string (Str) suffix - Optional : suffix string (Str) decimals - Optional : positive number of decimals in percent complete (Int) length - Optional : character length of bar (Int) fill - Optional : bar fill character (Str) """ percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total))) filledLength = int(length * iteration // total) bar = fill * filledLength + '-' * (length - filledLength) print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r') # Print New Line on Complete if iteration == total: print() #Тут начинаем смотреть, начинается мой быдлокод! def long_function(): # некая функция, которая выполняется какое-то время, # по времени она не однородна n=0 while n<10: if n<3: time.sleep(2) else: if n<8: time.sleep(3) else: if n<11: time.sleep(1) n=n+1 return n # собственно какой-то способ как отдавать на каждой итерации переменную l = 10 t = threading.Thread(target=long_function) t.start() printProgressBar(0, l, prefix = 'Progress:', suffix = 'Complete', length = 50) while t.is_alive(): # пока функция выполняется t.join(1) # f = long_function естественно это не работае. printProgressBar(f + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50) Meaning, there is a certain function, it is somehow executed, I want to track its progress in the future. Naryl in the open spaces, a way to implement progress.
The question is how do I place data from the function being executed in a separate thread into the variable f (while it is being executed and not when it ends)
