Answer the question
In order to leave comments, you need to log in
Distributing tasks to Python threads?
Hello!
At me the following task:
I connect 100 flows and I throw the general file with lines.
I need to make sure that the threads do not repeat each other and bring the matter to the end,
my solution is:
from threading import Thread as th
def bot():
global baza
for i in baza:
bi = i
baza.remove(i)
baza = open('baza.txt','r').read().split()
for i in range(30):
th(target=bot).start()
Answer the question
In order to leave comments, you need to log in
Everything has already been thought of for you. The standard library has a thread pool, to which you can pass a function, an array of data and the size of a piece processed by one thread, and then it will create threads and distribute data to them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question