writing output to a file with subprocess in python
<p>I have a code which spawns at the max 4 processes at a go. It looks for any news jobs submitted and if it exists  it runs the python code</p>

<pre><code>for index,row in enumerate(rows):
    if index &lt; 4:
        dirs=row[0]
        dirName=os.path.join(homeFolder,dirs)
        logFile=os.path.join(dirName,(dirs+".log"))
        proc=subprocess.Popen(["python","test.py",dirs],stdout=open(logFile,'w'))
</code></pre>

<p>I have few questions:</p>

<ol>
<li>When I try to write the output or errors in log file it does not write into the file until the process finishes.Is it possible to write the output in the file as the process runs as this will help to know at what stage it is running.</li>
<li>When one process finishes, I want the next job in the queue to be run rather than waiting for all child processes to finish and then the daemon starts any new.</li>
</ol>

<p>Any help will be appreciated.Thanks!</p>
