I know there are tons of questions like this one, I tried to read them all. What I'm doing is to use the multiprocessing library to parse web pages via Python Selenium. So, I have 3 lists to give to a function that processes them. First I write the function, then initiate the browser istance and lastly start the 3 processes.
import ...
def parsing_pages(list_with_pages_to_parse):
global browser
#do stuff
if __name__ == '__main__':
browser = webdriver.Chrome(..., options = ...)
browser.get(...)
lists_with_pages_to_parse = [ [...], [...], [...] ]
pool.mp.Pool(3)
pool.map(parsing_pages, lists_with_pages_to_parse)
pool.close
pool.join
The error:
NameError: name 'browser' is not defined
Traceback (most recent call last):
File "c:\Users\39338\Desktop\program.py", line 323, in <module>
pool.map(parsing_pages, lists_with_pages_to_parse)
File "C:\Users\39338\AppData\Local\Programs\Python\Python310\lib\multiprocessing\pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "C:\Users\39338\AppData\Local\Programs\Python\Python310\lib\multiprocessing\pool.py", line 771, in get
raise self._value
NameError: name 'browser' is not defined
I used global to allow "browser" to be used inside the function. I thought the problem was that the function is written before I create "browser", but when I try to put it after the main part, I get the error that the function cannot be found when called.