Note that there are some explanatory texts on larger screens.

plurals
  1. POAlways run a constant number of subprocesses in parallel
    primarykey
    data
    text
    <p>I want to use subprocesses to let 20 instances of a written script run parallel. Lets say i have a big list of urls with like 100.000 entries and my program should control that all the time 20 instances of my script are working on that list. I wanted to code it as follows:</p> <pre><code>urllist = [url1, url2, url3, .. , url100000] i=0 while number_of_subproccesses &lt; 20 and i&lt;100000: subprocess.Popen(['python', 'script.py', urllist[i]] i = i+1 </code></pre> <p>My script just writes something into a database or textfile. It doesnt output anything and dont need more input than the url.</p> <p>My problem is i wasnt able to find something how to get the number of subprocesses that are active. Im a novice programmer so every hint and suggestion is welcome. I was also wondering how i can manage it once the 20 subprocesses are loaded that the while loop checks the conditions again? I thought of maybe putting another while loop over it, something like</p> <pre><code>while i&lt;100000 while number_of_subproccesses &lt; 20: subprocess.Popen(['python', 'script.py', urllist[i]] i = i+1 if number_of_subprocesses == 20: sleep() # wait to some time until check again </code></pre> <p>Or maybe theres a bette possibility that the while loop is always checking on the number of subprocesses?</p> <p>I also considered using the module multiprocessing, but i found it really convenient to just call the script.py with subprocessing instead of a function with multiprocessing.</p> <p>Maybe someone can help me and lead me into the right direction. Thanks Alot!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload