I am trying to implement multiprocessing in my application on windows system.
The scenario is : From GUI, when i click "Run" button control comes to a python function(which is not a main function).
Now in this function I am running loop and reading/executing multiple file one at a time. I want this to happen in parallel.
But as multiprocessing.process() need __name__ ='__main__', my function mentioned in "target = function name" in multiprocessing() is not being invoked.
How can I make it happen. If multiprocessing seems wrong way then any alternative way to improve code performance?
Adding Sample code(please note that this is just a psudo code where i have added high level code to understand the flow, please excuse any syntax error) :
urls.py file:
from django.urls import path
from textapp import views
urlpatterns = [
path('execute/',views.functiontomultiprocess),
...
other urls
]
views.py:
def functiontomultiprocess(request):
nprocess = []
for doc in alldocs:
p = multiprocess.Process(function2)
p.start() # start process
nprocess.append(p)
for p1 in nprocess:
p1.join()