It's not too difficult:<div><br></div><div># subp.py</div><div><br></div><div><div>import sys</div><div>import time</div><div><br></div><div>for i in range(10):</div><div>    sys.stdout.write('I am subprocess\n')</div>
<div>    sys.stdout.flush()  # this may not be necessary</div><div>    time.sleep(1)</div><div><br></div><div># writer.py</div><div><br></div><div><div>import subprocess</div><div>import time</div><div><br></div><div>subp = subprocess.Popen(['/usr/bin/python', '-u', './subp.py'], stdout=subprocess.PIPE)</div>
<div><br></div><div>while True:</div><div>    time.sleep(1)</div><div>    print('I am main process.') # write this to one section of the file</div><div>    </div><div>    if subp.poll() != None: # the subprocess has terminated        </div>
<div>        break</div><div>        </div><div>    stdout = subp.stdout.readline()        </div><div>    print(stdout) # write this to the other section</div><div><br></div><div><br></div><div><br></div><div><div>brucewayne@broo:~/Documents$ python ./writer.py</div>
<div>I am main process.</div><div>I am subprocess</div><div><br></div><div>I am main process.</div><div>I am subprocess</div><div><br></div><div>I am main process.</div><div>I am subprocess</div><div><br></div><div>I am main process.</div>
<div>I am subprocess</div><div><br></div><div>I am main process.</div><div>I am subprocess</div><div><br></div><div>I am main process.</div><div>I am subprocess</div><div><br></div><div>I am main process.</div><div>I am subprocess</div>
<div><br></div><div>I am main process.</div><div>I am subprocess</div><div><br></div><div>I am main process.</div><div>I am subprocess</div><div><br></div><div>I am main process.</div><div>I am subprocess</div><div><br></div>
<div>I am main process.</div><div><br></div></div></div><div><br></div><br><div class="gmail_quote">On Thu, Mar 18, 2010 at 12:52 AM, Steve Holden <span dir="ltr"><<a href="mailto:steve@holdenweb.com">steve@holdenweb.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Chris Colbert wrote:<br>
[top-posting switched to bottom-posting]<br>
<div class="im">><br>
> On Thu, Mar 18, 2010 at 12:20 AM, Gabriel Genellina<br>
</div><div class="im">> <<a href="mailto:gagsl-py2@yahoo.com.ar">gagsl-py2@yahoo.com.ar</a> <mailto:<a href="mailto:gagsl-py2@yahoo.com.ar">gagsl-py2@yahoo.com.ar</a>>> wrote:<br>
><br>
>     En Wed, 17 Mar 2010 23:42:46 -0300, <<a href="mailto:python@bdurham.com">python@bdurham.com</a><br>
</div>>     <mailto:<a href="mailto:python@bdurham.com">python@bdurham.com</a>>> escribió:<br>
<div class="im">><br>
><br>
>         Is there a way to open a file for shared write mode under<br>
>         Windows?<br>
><br>
>         I have 2 processes that will write to different regions of this<br>
>         shared file.<br>
><br>
><br>
>     Using the pywin32 package at sourceforge, you have access to the<br>
>     CreateFile function:<br>
>     <a href="http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx</a><br>
>     You want dwShareMode=FILE_SHARE_WRITE<br>
><br>
</div><div class="im">> you could also just have one process do the writing for both processes<br>
> via pipes.<br>
<br>
</div>You could, but then you'd have to work out how to avoid blocking on one<br>
pipe when data was available form the other. Or is this trivially easy,<br>
and I just don't know enough about pipes?<br>
<br>
regards<br>
 Steve<br>
<font color="#888888">--<br>
Steve Holden           +1 571 484 6266   +1 800 494 3119<br>
See PyCon Talks from Atlanta 2010  <a href="http://pycon.blip.tv/" target="_blank">http://pycon.blip.tv/</a><br>
Holden Web LLC                 <a href="http://www.holdenweb.com/" target="_blank">http://www.holdenweb.com/</a><br>
UPCOMING EVENTS:        <a href="http://holdenweb.eventbrite.com/" target="_blank">http://holdenweb.eventbrite.com/</a><br>
</font><div><div></div><div class="h5"><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>