Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何并行多次运行单个python函数_Python_Multithreading_Selenium_Selenium Webdriver_Python Multiprocessing - Fatal编程技术网

如何并行多次运行单个python函数

如何并行多次运行单个python函数,python,multithreading,selenium,selenium-webdriver,python-multiprocessing,Python,Multithreading,Selenium,Selenium Webdriver,Python Multiprocessing,我有一个python函数,我想并行运行100次。代码是什么 from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.headless = True options.ad

我有一个python函数,我想并行运行100次。代码是什么

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


options = Options()
options.headless = True
options.add_experimental_option("excludeSwitches", ['enable-automation']);
options.add_argument('--user-agent="Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 640 XL LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166"')
CHROMEDRIVER_PATH = 'c:\webdrivers\chromedriver.exe'
driver = webdriver.Chrome(CHROMEDRIVER_PATH, options=options)
def true():
    driver.get('https://youtu.be/Uhr5J5Sj-fU')
    driver.find_element_by_xpath('//*[@id="movie_player"]/div[2]/button/div').click()
    time.sleep(12*60+30)
    driver.quit()

使用python的线程模块 这可能对你有帮助

导入线程
def hi():
打印('hi')
对于范围(0100)内的i:
t=线程。线程(目标=高)
t、 开始()

您希望代码的哪一部分并行运行100次?您可能会对该模块感兴趣。true()函数您是否介意发布您迄今为止试图并行运行代码的内容?请注意,线程模块可能无法提供真正的并行性,因为CPython实现中存在全局解释器锁me@KeshavReddy--更详细地解释,但基本上意味着多线程不会加快CPU密集型操作。不,这一点都不密集。我愿意并行运行该函数10次,并且使用的cpu不到20%