files in non-blocking mode?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Uwe Mayer

    #1

    files in non-blocking mode?

    Hi,

    I want two python programs to communicate over stdIO channels. The one
    executes the other via the popen3 function:

    amc = Popen3("./amc/amc.py", True, 0)
    line = stdin.readline( )
    amc.tochild.wri te(line)
    amc.tochild.flu sh()
    print amc.fromchild.r eadlines()

    The problem is that although amc.tochild gets flushed the data never reaches
    the client until the .tochild fd is closed. Is there any way to put IO
    channels into non-blocking mode in python?

    Thanks
    Uwe
  • Mathias Waack

    #2
    Re: files in non-blocking mode?

    Uwe Mayer wrote:
    [color=blue]
    > Hi,
    >
    > I want two python programs to communicate over stdIO channels. The
    > one executes the other via the popen3 function:
    >
    > amc = Popen3("./amc/amc.py", True, 0)
    > line = stdin.readline( )
    > amc.tochild.wri te(line)
    > amc.tochild.flu sh()
    > print amc.fromchild.r eadlines()
    >
    > The problem is that although amc.tochild gets flushed the data
    > never reaches the client until the .tochild fd is closed. Is there
    > any way to put IO channels into non-blocking mode in python?[/color]

    How do you read the data in the client? Maybe you're using a line
    buffered read? Does your code work if the server includes a trailing
    CR and/or NL in the string before it calls the flush?

    Mathias

    Comment

    • Uwe Mayer

      #3
      Re: files in non-blocking mode?

      Sunday 28 November 2004 14:49 pm Mathias Waack wrote:
      [color=blue]
      > Uwe Mayer wrote:[color=green]
      >> I want two python programs to communicate over stdIO channels. The
      >> one executes the other via the popen3 function:
      >>
      >> amc = Popen3("./amc/amc.py", True, 0)
      >> line = stdin.readline( )
      >> amc.tochild.wri te(line)
      >> amc.tochild.flu sh()
      >> print amc.fromchild.r eadlines()
      >>
      >> The problem is that although amc.tochild gets flushed the data
      >> never reaches the client until the .tochild fd is closed. Is there
      >> any way to put IO channels into non-blocking mode in python?[/color][/color]
      [color=blue]
      > How do you read the data in the client? Maybe you're using a line
      > buffered read? Does your code work if the server includes a trailing
      > CR and/or NL in the string before it calls the flush?[/color]

      Yes, I used

      line = stdin.readline( )

      and made sure the sending client had a newline ("\n") char appended to the
      text. Still, the receiving client's readline() function does not return.

      Uwe

      Comment

      • Jean Brouwers

        #4
        Re: files in non-blocking mode?


        Try setting the unbuffered mode for the spawned process by using

        "python -u ./amc/amc.py"


        /Jean Brouwers


        In article <cocrun$qqu$1@n ews2.rz.uni-karlsruhe.de>, Uwe Mayer
        <merkosh@hadiko .de> wrote:
        [color=blue]
        > Sunday 28 November 2004 14:49 pm Mathias Waack wrote:
        >[color=green]
        > > Uwe Mayer wrote:[color=darkred]
        > >> I want two python programs to communicate over stdIO channels. The
        > >> one executes the other via the popen3 function:
        > >>
        > >> amc = Popen3("./amc/amc.py", True, 0)
        > >> line = stdin.readline( )
        > >> amc.tochild.wri te(line)
        > >> amc.tochild.flu sh()
        > >> print amc.fromchild.r eadlines()
        > >>
        > >> The problem is that although amc.tochild gets flushed the data
        > >> never reaches the client until the .tochild fd is closed. Is there
        > >> any way to put IO channels into non-blocking mode in python?[/color][/color]
        >[color=green]
        > > How do you read the data in the client? Maybe you're using a line
        > > buffered read? Does your code work if the server includes a trailing
        > > CR and/or NL in the string before it calls the flush?[/color]
        >
        > Yes, I used
        >
        > line = stdin.readline( )
        >
        > and made sure the sending client had a newline ("\n") char appended to the
        > text. Still, the receiving client's readline() function does not return.
        >
        > Uwe[/color]

        Comment

        Working...