I am aware that this question has already been asked, but I have done extensive research and am unable to figure my problem out.
My question has to do with running complex functions in parallel.
I'm using selenium webdriver to automatically download files from one website and upload them to another, and I want these functions to run at the same time. They both use while loops and have layered conditional statements. I cannot get the functions to run at the same time and would appreciate help. My code is as follows:
import multiprocessing
def auto_download():
# function logic here
def auto_upload():
# function logic here
if __name__ == '__main__':
p1 = multiprocessing.Process(name='auto download', target=auto_download())
p2 = multiprocessing.Process(name='auto upload', target=auto_upload())
p1.start()
p2.start()
This code runs the first function auto_download() but never starts the second.
However, if I run the following code from here, which is the same idea but with much simpler functions, it works fine.
import multiprocessing
import time
def add():
while True:
print (1)
time.sleep(3)
def sud():
while True:
print(0)
time.sleep(3)
if __name__ == '__main__':
p1 = multiprocessing.Process(name='p1', target=add)
p = multiprocessing.Process(name='p', target=sud)
p1.start()
p.start()
Does my problem stem from the complexity of the functions I am trying to run simultaneously? Thanks ahead of time for your help!
EDIT: The solution (thanks to Raw Dawg) is that I was calling the function directly instead of in the process object. This is different than the solutions for this question. The following code fixes the problem:
p1 = multiprocessing.Process(name='auto download', target=auto_download)
p2 = multiprocessing.Process(name='auto upload', target=auto_upload)
p1.start()
p2.start()