Answer the question
In order to leave comments, you need to log in
Why are queries executed sequentially?
There is a class that parses some content. I initialize it with a specific link to the page, it works and outputs the result to the console.
since there are a lot of links to pages, I tried to parallelize this process using a loop:
from multiprocessing import Process
for link in links:
img_recognizer = ImgRecognizer(someArgs)
proc = Process(target=img_recognizer.get_phone())
procs.append(proc)
proc.start()
for proc in procs:
proc.join()
Answer the question
In order to leave comments, you need to log in
Read documentation:
>>> help(Process.join)
join(self, timeout=None)
Wait until child process terminates
from multiprocessing import Process
from time import sleep
def worker(n):
print("the worker went to the office")
sleep(n)
print("the worker has been walking for %d sec" % n)
if __name__ == "__main__":
plist = []
for i in range(4, 0, -1):
proc = Process(target=worker, args=(i,))
plist.append(proc)
for proc in plist:
proc.start()
the worker went to the office
the worker went to the office
the worker went to the office
the worker went to the office
the worker has been walking for 1 sec
the worker has been walking for 2 sec
the worker has been walking for 3 sec
the worker has been walking for 4 sec
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question