Python Forum
How to run multiple threads properly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run multiple threads properly
#6
okay, so after some time adopting the above approach, I can finally reply.

Cry This doesn't work :

Quote:
_=[threading.Thread(target=csv2xlsx, args=(file_name,)).start()forfile_nameinfiles_list]

It might work as 

    for file_name in CSVFILES:
        threading.Thread(target=MAIN_CSV, args=(file_name,)).start()
...which I will go and test now :

main_INIT.py (main init and core script - will run the below scripts as threads)
main_process_PDF.py
main_process_CSV.py (processes the CSV files simultaneously with threads) 

So in essence :

#this is main_INIT.py
#do something

#run function from main_process_PDF.py
#run function from main_process_CSV.py
#is function from main_process_PDF.py done ? is function from main_process_CSV.py done ? If both = yes, continue, else = wait .

#do something
This doesn't work. In both cases, running it alone or inside a function, the CSV processes will not wait until all are done. They will simply run over to the next part of the script.  Cry

...then I also tried

[python]
    for file_name in CSVFILES:
        threading.Thread(target=MAIN_CSV, args=(file_name,)).start()
        threading.Thread(target=MAIN_CSV, args=(file_name,)).join()
[python/]
Reply


Messages In This Thread
RE: How to run multiple threads properly - by wavic - Dec-22-2017, 07:38 AM
RE: How to run multiple threads properly - by mpd - Dec-22-2017, 12:41 PM
RE: How to run multiple threads properly - by wavic - Dec-22-2017, 02:42 PM
RE: How to run multiple threads properly - by cyberion1985 - Dec-29-2017, 08:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to separate a loop across multiple threads stylingpat 0 2,148 May-05-2021, 05:21 PM
Last Post: stylingpat
  Get average of multiple threads Contra_Boy 1 23,066 May-05-2020, 04:51 PM
Last Post: deanhystad
  stop multiple threads jeuvrey 5 4,581 Nov-15-2018, 01:34 PM
Last Post: jeuvrey
  Quitting multiple threads MuntyScruntfundle 3 3,438 Oct-17-2018, 05:14 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020