Answer the question
In order to leave comments, you need to log in
How to solve the problem with multithreading?
def new_therad(eth_list, all_string, count):
list_all = []
for i in range(len(eth_list)):
if eth_list[i] in blacklist:
continue
list_all.append(Thread(target=get_data, args=(eth_list[i], all_string[i])))
blacklist.append(eth_list[i])
if len(list_all) == count:
print('Собрано нужное количество потоков, запуск')
for i in range(len(list_all)):
loop.run_until_complete(run_thread(list_all[i], i+1))
if len(blacklist) == MainFileLen.count:
pass
else:
new_therad(eth_list, all_string, count)
async def run_thread(thread, num):
thread.start()
thread.join()
print(f'Поток номер {num} завершен')
Answer the question
In order to leave comments, you need to log in
Thanks to those who helped, now the code looks like this:
def new_therad(eth_list, all_string, count):
for i in range(len(eth_list)):
if threading.active_count() == count-1:
time.sleep(1)
flow1 = Thread(target=get_data, args=(eth_list[i], all_string[i]), daemon=True)
flow1.start()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question