简体   繁体   English

使用Selenium和python进行多重处理

[英]Multiprocessing using selenium and python

I am trying to run the same process many times, at the same time. 我试图在同一时间多次运行相同的过程。 The issue I am having right now is that the program only runs one at a time and waits until that process is done to start a new one. 我现在遇到的问题是该程序一次只运行一个,然后等待该过程完成以启动新的程序。

I am not sure how to have them running side by side at the same time. 我不确定如何让它们同时运行。

pool = Pool(processes=2)
item1 = pool.apply_async(run_bot(item_keyword, PROXY))
item2 = pool.apply_async(run_bot(item_keyword, PROXY))

pool.close()
pool.join()

it could happen if both of ur bots' browsers use the same user-data-dir path 如果两个ur bot的浏览器都使用相同的user-data-dir 路径,则可能会发生

there's an argument for chrome: chrome有一个参数:

--user-data-dir=path

For anyone who might need this, this is how I solved it: 对于可能需要此功能的任何人,这就是我解决的方法:

instance_number = len(proxy_list)

for i in range(instance_number):
    item_keyword = item_keywords_list[i]
    PROXY = proxy_list[i]
    instance[i] = multiprocessing.Process(target=run_bot, args=(item_keyword, PROXY, year, month, day, hour, minute))

for i in range(0, instance_number, 1):
    instance[i].start()

for i in range(0, instance_number, 1):
    instance[i].join()

You don't need the 您不需要

for in in range(instance_number):

I did it that way so I can scale this easier in the future. 我这样做是为了将来可以更轻松地进行扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM