【发布时间】:2017-06-09 04:35:09
【问题描述】:
我正在使用 python 多处理库来执行 selenium 脚本。我的代码如下:
#-- start and join multiple threads ---
thread_list = []
total_threads=10 #-- no of parallel threads
for i in range(total_threads):
t = Process(target=get_browser_and_start, args=[url,nlp,pixel])
thread_list.append(t)
print "starting thread..."
t.start()
for t in thread_list:
print "joining existing thread..."
t.join()
据我了解join() 函数,它将等待每个进程完成。但是我希望一旦一个进程被释放,它就会被分配另一个任务来执行新的功能。
可以这样理解:
假设首先启动了 8 个进程。
no_of_tasks_to_perform = 100
for i in range(no_of_tasks_to_perform):
processes start(8)
if process no 2 finished executing, start new process
maintain 8 process at any point of time till
"i" is <= no_of_tasks_to_perform
【问题讨论】:
标签: python selenium-webdriver python-multiprocessing