我有一个数组,例如100个项目,我想为我的数组的每10个项目运行10个线程。你知道吗
我的问题是,我不知道如何使用for循环为第一个10项、第二个10项等运行10个线程
我需要的是:
for item in myarray:
thread.start_new_thread(first_item)
thread.start_new_thread(second_item)
thread.start_new_thread(third_item)
thread.start_new_thread(fourth_item)
thread.start_new_thread(fifth_item)
thread.start_new_thread(sixth_item)
thread.start_new_thread(seventh_item)
thread.start_new_thread(eight_item)
thread.start_new_thread(ninth_item)
thread.start_new_thread(tenth_item)
对于for循环的第二轮,运行第二个10项的线程。你知道吗
如何每次将for循环的索引增加10倍?你知道吗
这是值得怀疑的设计,因为:
常见的方法是使用线程池。您可以在
concurrent.futures
中搜索Python3.2+,或者在较旧的版本(也不是太旧…multiprocessing.pool.ThreadPool
)中搜索。你知道吗相关问题 更多 >
编程相关推荐