多处理是否在一个内核上运行

问题描述

我正在阅读硒的多处理,以了解它与硒的多线程相比的优势。

我了解计算机具有核心,例如我的有4个,并且计算机具有逻辑核心,例如我的也有4个。

我想了解的是,当我使用多处理时,是在一个内核上完成所有操作,如果是,则是哪一个?就像我的计算机或其他内核使用的主要内核一样。

是否还可以选择一个内核上要有多少个进程,并且应该有限制。

我的问题(如果不清楚)

  1. 多处理是否全部在一个内核上发生

  2. 您可以选择一个核心上要多少个进程

  3. 您在一个核心上有多少个进程应该有限制

这是我的代码

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys

import time
import multiprocessing



class go():
    def __init__(self):
        self.run()
    def run(self):
        options = webdriver.ChromeOptions()
        options.add_argument('--headless',)
        self.browser = webdriver.Chrome('chromedriver.exe',options=options)
        self.browser.get('https://www.wikipedia.org/')

        webdriverwait(self.browser,10).until(
            EC.presence_of_element_located((By.ID,"searchInput"))).send_keys('Python',Keys.ENTER)
        time.sleep(3)
        print('Moved To Next Section ')

        webdriverwait(self.browser,10).until(
            EC.presence_of_element_located((By.PARTIAL_LINK_TEXT,"Computing"))).click()
        time.sleep(3)
        print('Moved To Next Section ')

        webdriverwait(self.browser,"People"))).click()
        time.sleep(3)

        print('Moved To Next Section ')
        webdriverwait(self.browser,"Roller coasters"))).click()
        time.sleep(3)

        print('Moved To Next Section ')
        webdriverwait(self.browser,"Vehicles"))).click()
        time.sleep(3)

        print('Moved To Next Section ')
        webdriverwait(self.browser,"Weaponry"))).click()
        time.sleep(100)



if __name__ == "__main__":

    for count in range(10):
        multiprocessing.Process(target=go).start()

解决方法

多处理是否全部在一个内核上发生

您可以选择一个核心上要多少个进程

一个核心上有多少个进程应该有限制 如果有限制,什么是最好的解决方法

这不是您通过python代码执行的操作。操作系统由它负责。对于用户而言,线程或进程的数量实际上没有限制。

Meny Issakov是正确的,您应该阅读python中的多处理。