Python Forum
How to to tie the execution of one process to another inside a loop in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to to tie the execution of one process to another inside a loop in Python
#1
How can I keep a loop going, while having some processes that are waiting for others inside the loop? (see the code below for clarification, it makes more sense to explain in code). PS: I'm using Popen from the multithreading module

for i in range(0, len(my_list), batch_size):
    current_batch = my_list[i:i+batch_size]
    download_processes = [Popen('do stuff')] # NOT ACTUAL CODE. This downloads files.
    _ = [p.wait() for p in download_processes] # wait until all files above download before executing the code below 

    more_processes = [Popen('do stuff')] # NOT ACTUAL CODE. This zips the downloaded files
    # execute yet more processes (that process the zips files) when "more_processes" end, but keep the loop going to start downloading more files
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Break within an if statement inside a while loop not working Python_more_on 2 1,893 Sep-03-2025, 12:55 AM
Last Post: Pedroski55
  Trying to get JSON object in python and process it further Creepy 2 1,583 Oct-24-2024, 08:46 AM
Last Post: buran
  kill python execution program lebossejames 0 1,149 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  Variable definitions inside loop / could be better? gugarciap 2 2,108 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 14,916 Nov-07-2023, 09:49 AM
Last Post: buran
  Question about Creating an Automated Process in Python Supratik1234 0 1,519 Jan-13-2023, 08:29 PM
Last Post: Supratik1234
  Help adding a loop inside a loop Extra 31 12,046 Oct-23-2022, 12:16 AM
Last Post: Extra
  Confused about python execution jpezz 4 4,092 Oct-09-2022, 06:56 PM
Last Post: Gribouillis
  Process the image on the Python HTTP server Aleks 0 4,803 Dec-02-2021, 11:43 PM
Last Post: Aleks
  How to measure execution time of a multithread loop spacedog 2 4,816 Apr-24-2021, 07:52 AM
Last Post: spacedog

Forum Jump:

User Panel Messages

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