'Multiprocessing doesn't work with Selenium in Python

I am being honest, so the reason I use Selenium is because I try to make instagram spam-bot which will send messages to many people where I will ask them to not to be quiet about Russian invasion in Ukraine, because I'm Ukrainian and it's so awful and terrifying what happens around. And this is my duty to help to stop it as mush as I can!

Explanation: Here is the multishare() function which is called from another function that creates self.followers set, that contains usernames of people who will be sent text. In multishare() function I redefine self.followers as a list and separate it into 4 equal parts to make spammer four times faster. And then I call share() function through the multiprocessing, but it doesn't even open Chrome. Below you see the code. Here is the code:

    def multishare(self):
        self.followers = list(self.followers)
        ftq = int(len(self.followers) // 4)
        sq = int(len(self.followers) // 2)
        tq = int(len(self.followers) // 1.33)
        fhq = len(self.followers)
        first_part = self.followers[0:ftq]
        second_part = self.followers[ftq:sq]
        third_part = self.followers[sq:tq]
        fourth_part = self.followers[tq:fhq]
        self.followers = [first_part, second_part, third_part, fourth_part]

        pool = Pool(processes=4)
        pool.map(self.share, self.followers)

    def share(self, users):
        self.safe_get('https://www.instagram.com/')
        for user in users:
            time.sleep(1)
            self.safe_get('https://www.instagram.com/direct/inbox/')
            self.element_existence('//*[@id="react-root"]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button').click()
            time.sleep(1)
            search_user = self.element_existence('/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input')
            search_user.clear()
            time.sleep(1)
            search_user.send_keys(user)
            time.sleep(1)
            self.element_existence("/html/body/div[6]/div/div/div[2]/div[2]/div[1]/div/div[3]/button").click()
            time.sleep(1)
            self.element_existence("/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input").click()

And that's the errors that I got:

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/timeouts (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa5089d4250>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:


urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused'))

So I cant actually solve this. **It's not about multiprocessing, my main target is to make spammer as fast as it possible. So if u have better idea or just know how to solve my issue, help me please !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source