Writing Parallelly into two files python
<p>I am just trying to write parallelly in to two file with the help of threading.</p>

<pre><code>def dmesg (i):

    cmd = 'dmesg'
    print cmd
    (status, cmd_out) = commands.getstatusoutput(cmd)
    fil = open('dmesg_logs', 'w')
    fil.write(cmd_out)
    fil.close()

def dump (i):

    cmd = 'lsmod'
    print cmd
    (status, cmd_out) = commands.getstatusoutput(cmd)
    fil = open('logs', 'w')
    fil.write(cmd_out)
    fil.close()
if __name__ == "__main__":

    t1 = threading.Thread(target = dmesg, args=(0,))
    t1.start()
    t2 = threading.Thread(target = dump, args=(0,))
    t2.start()
    while True : 
        "My own code"
</code></pre>

<p>Here my problem is logs file is not created in thread 2. Can i iknow what am doing wrong ?</p>

<pre><code>cmd = ['dmesg']
with open ('dmesg_log.txt', 'w') as out1:
    retun1 = subprocess.Popen(cmd, shell = True, stdout=out1)
</code></pre>

<p>Found the solution. Above code works for me.</p>

python python-2.7