subprocess - Avoid deadlock using Popen without using sleep (Python 2.7) -


i have problem deadlock using python script parses output produced piping 2 programs , stores result in directory x.

import subprocess sp time import sleep  p1 = sp.popen(['executable_1'], stdout=sp.pipe , stderr = sp.stdout) p2 = sp.popen(['executable_2'], stdin=p1.stdout, stdout = sp.pipe)  x = my_parser(p2.stdout) 

however if change script using p2 = sp.popen(executable_2, stdin=p1.stdout, stdout = sp.pipe, preexec_fn = time.sleep(0.1)) seems working fine.

the solution though doesn't seem clean me. understand waiting bit of time give possibility p1 flush output stdout, (although if manually try p1.stdout.flush() ioerror well).

i can't use communicate() because output of p2 quite large , want process data while executable_2 still in execution.

how can prevent deadlock in case without using sleep()?


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -