0

I have tried to search for this answer, but all responses seem to be very much "The answer depends on exactly what you are trying to do" and none of the question askers are asking a similar thing to my need, so here goes...

I have a python script that takes input from user, and then checks network drives for files and contents of files if they exist (6 different network drives to be precise) and runs some SQL queries too. The issue is that each check can take up to a minute or two due to network speeds and everyone working from home, etc. This means that it can take a long time between user input and result.

Is it possible to run these functions simultaniously and recieve the results (dictionaries usually I think, if that matters) back in an unknown order (i.e. not nessesarily in the order they were executed).

Thank you in advance for any help.

Aaron Doyle
  • 23
  • 1
  • 6
  • What you're looking for is `Threads`. Create a Thread for every function and wait for each Thread to finish. Once they're done, retrieve the output from the Threads in any order you want, concatenate and send back. Refer to this to see how to wait for threads https://stackoverflow.com/questions/11968689/python-multithreading-wait-till-all-threads-finished – thethiny Feb 25 '21 at 11:41
  • Try using [multiprocessing](https://docs.python.org/3/library/multiprocessing.html) or [multithreading](https://www.geeksforgeeks.org/multithreading-python-set-1/) – Hunter Feb 25 '21 at 11:42
  • Look into threading, or asyncio and just supply the user input in a queue. – hyred- Feb 25 '21 at 11:42
  • *run these functions simultaniously and recieve the results (dictionaries usually I think, if that matters) back in an unknown order (i.e. not nessesarily in the order they were executed).* - this sound linke description of task queue system for me – Daweo Feb 25 '21 at 11:50
  • Thank you all. The link in the first comment looks perfect. Thanks all! – Aaron Doyle Feb 25 '21 at 13:52
  • Confirmed that the link in the first comment works amazing! Thank you. – Aaron Doyle Feb 26 '21 at 16:27

0 Answers0