实际上这里是新的,我会尽我最大的努力来描述我的问题。我有一个for循环,我想通过线程来执行这个for循环。像这样:
for i in range(0,100):
print(i)我想要4-5个线程来执行它并打印i的值(记住不要运行4-5次相同的循环)。好的,我将以另一种方式描述相同的内容:
我有10个文本框在一个网页上,我想填满所有的框,以填补硒。我怎么做呢?我使用for循环,如下所示:
for texbox in texoxelements:
textbox.send_keys(texoxelements.index)在这里,我想将所有的TEXTBOXES填充到一个循环中,并使用线程,因为所有的TEXTBOXES都应该填充在SECOEND中。
下面是另一个例子:
def myfunc(number):
for i in range(0,number):
print(i)#or do some other stuffs
#here i want something to execute that function once and solve that forloop in a threading method for which
#it will take less that a secoend to do stuffs and complete the for loop.
#_____Like_______
myfunc(25)
#and it should print 25 in in that for loop ad using of threading.
#secuence print is not mandatory我希望我能够在两个example.Can中描述我的问题,有人能帮我吗?我是新来的,.Small很友好。
发布于 2021-11-23 10:21:32
使用池。
from multiprocessing.pool import ThreadPool
def worker(index, texbox):
texbox.send_keys(index)
workers = 4
pool = ThreadPool(workers)
pool.starmap(worker, enumerate(texoxelements))https://stackoverflow.com/questions/70078974
复制相似问题