FAQ
Hi,

What I am trying to do is to run a subprocess on another machine using
subprocess.Popen, this subprocess contuinue writing something into a
file when it is runing.

After submit this subprocess, I tried to open the file and readlines()
in the loop (with a delay) in the loop) when the subprocess was
runing.

The problem is I could not get anything untill the subprocess
finished.

I also tried to run another python programm when the subprocess is
runing, I could get what I want.

Does anyone know why? Thanks!

JD

Search Discussions

  • Adrian Petrescu at Aug 2, 2007 at 5:00 pm

    On Aug 2, 12:41 pm, JD wrote:
    Hi,

    What I am trying to do is to run a subprocess on another machine using
    subprocess.Popen, this subprocess contuinue writing something into a
    file when it is runing.

    After submit this subprocess, I tried to open the file and readlines()
    in the loop (with a delay) in the loop) when the subprocess was
    runing.

    The problem is I could not get anything untill the subprocess
    finished.

    I also tried to run another python programm when the subprocess is
    runing, I could get what I want.

    Does anyone know why? Thanks!

    JD
    Could the problem be that the subprocess only flushes the output
    buffer when it terminates, and so until the subprocess "finishes", as
    you say, the file is empty because the data is still in the buffer?
    Trying throwing some flushes into the code and see if it helps.

    Or am I misunderstanding your question?
  • JD at Aug 2, 2007 at 5:10 pm
    Thanks for answering,

    No, the data was writing into the file when the subprocess was
    runing.

    For example, every second it will write something into the file.

    I tried to run another python program aside and it sucessfully read
    the file when the subprocess was runing.

    JD
    On Aug 2, 11:00 am, Adrian Petrescu wrote:
    On Aug 2, 12:41 pm, JD wrote:


    Hi,
    What I am trying to do is to run a subprocess on another machine using
    subprocess.Popen, this subprocess contuinue writing something into a
    file when it is runing.
    After submit this subprocess, I tried to open the file and readlines()
    in the loop (with a delay) in the loop) when the subprocess was
    runing.
    The problem is I could not get anything untill the subprocess
    finished.
    I also tried to run another python programm when the subprocess is
    runing, I could get what I want.
    Does anyone know why? Thanks!
    JD
    Could the problem be that the subprocess only flushes the output
    buffer when it terminates, and so until the subprocess "finishes", as
    you say, the file is empty because the data is still in the buffer?
    Trying throwing some flushes into the code and see if it helps.

    Or am I misunderstanding your question?
  • Larry Bates at Aug 2, 2007 at 6:11 pm

    JD wrote:
    Hi,

    What I am trying to do is to run a subprocess on another machine using
    subprocess.Popen, this subprocess contuinue writing something into a
    file when it is runing.

    After submit this subprocess, I tried to open the file and readlines()
    in the loop (with a delay) in the loop) when the subprocess was
    runing.

    The problem is I could not get anything untill the subprocess
    finished.

    I also tried to run another python programm when the subprocess is
    runing, I could get what I want.

    Does anyone know why? Thanks!

    JD
    I believe you are approaching this incorrectly. You should probably be using a
    socket server/socket client to communicate between these two. Or perhaps you
    could use a multi-user database table. Writing/reading to files from two
    different workstations and expecting them to by synchronized most likely won't work.

    -Larry
  • JD at Aug 2, 2007 at 9:05 pm
    Thanks for the suggestion, I am thinking implement a database system
    for that.

    JD
    On Aug 2, 12:11 pm, Larry Bates wrote:
    JD wrote:
    Hi,
    What I am trying to do is to run a subprocess on another machine using
    subprocess.Popen, this subprocess contuinue writing something into a
    file when it is runing.
    After submit this subprocess, I tried to open the file and readlines()
    in the loop (with a delay) in the loop) when the subprocess was
    runing.
    The problem is I could not get anything untill the subprocess
    finished.
    I also tried to run another python programm when the subprocess is
    runing, I could get what I want.
    Does anyone know why? Thanks!
    JD
    I believe you are approaching this incorrectly. You should probably be using a
    socket server/socket client to communicate between these two. Or perhaps you
    could use a multi-user database table. Writing/reading to files from two
    different workstations and expecting them to by synchronized most likely won't work.

    -Larry

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 2, '07 at 4:41p
activeAug 2, '07 at 9:05p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2021 Grokbase