popen2 trouble

Discussion in 'Python' started by Diez B. Roggisch, Apr 2, 2004.

  1. Hi,

    I'm using the popen2 module to communicate with the crm114 text
    classificator. First I used to create a subprocess, feed the text to
    classify to it, close the crm's stdin file and read the results. Easy
    enough.

    However, the crm114 is a slow beast, and I try to increase its performanc by
    using it in the "window"-mode. That means that the text fed to the
    subprocess looks like this:

    ---START---
    including bfast
    ---STOP---

    The start/stop is detected by the crm114, and everything inbetween is
    subject to classification. This simple protocol allows multiple
    classifications without terminating the crm114 subprocess in between.

    When performing this in my console window, everything works as expected. I
    can paste several blocks of text that look like the above one, and the
    crm114 constantly outputs classification results.

    But when I try it from python like this


    out, inn, err = _.get_crminstance(path, _.classify_program)

    t = '%s\n%s\n%s\n' % (_.START, text, _.STOP)
    logger.debug(t)
    inn.write(t)
    inn.flush()
    #inn.close()

    res = out.read().strip()
    e = err.read().strip()

    my program hangs. Uncommenting the inn.close() helps somewhat as then the
    out.read() returns, but only after a minute or so. And I don't want to
    close it anyway, because I want to use it for the next classification.

    Any suggestions? I know that there are subtle differences between files and
    tenminals, but I'm no unix expert, so I'm somewtaht lost.

    --
    Regards,

    Diez B. Roggisch
    Diez B. Roggisch, Apr 2, 2004
    #1
    1. Advertising

  2. Diez B. Roggisch

    Armin Rigo Guest

    Hello Diez,

    "Diez B. Roggisch" wrote:
    > When performing this in my console window, everything works as expected. I
    > can paste several blocks of text that look like the above one, and the
    > crm114 constantly outputs classification results.


    Try using the 'bufsize' optional argument in the call to popen2. Set it
    to 0 to disable all buffering, if you are writing in large chunks (e.g.
    calling inn.write(bigstring)).


    Armin
    Armin Rigo, Apr 3, 2004
    #2
    1. Advertising

  3. > Try using the 'bufsize' optional argument in the call to popen2. Set it
    > to 0 to disable all buffering, if you are writing in large chunks (e.g.
    > calling inn.write(bigstring)).


    That didn't work - now I'm using pexpect, which simulates a tty.

    --
    Regards,

    Diez B. Roggisch
    Diez B. Roggisch, Apr 5, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guy

    popen2

    Guy, Aug 12, 2003, in forum: Python
    Replies:
    1
    Views:
    2,835
    Donn Cave
    Aug 12, 2003
  2. cherico

    popen2 with large input

    cherico, Jan 29, 2004, in forum: Python
    Replies:
    2
    Views:
    317
    Jeff Epler
    Jan 29, 2004
  3. A. Lloyd Flanagan

    Possible problem with popen2 module

    A. Lloyd Flanagan, Apr 30, 2004, in forum: Python
    Replies:
    2
    Views:
    303
    A. Lloyd Flanagan
    May 3, 2004
  4. Rembrandt Q Einstein

    Trouble with popen2

    Rembrandt Q Einstein, Sep 27, 2004, in forum: Python
    Replies:
    4
    Views:
    426
  5. Daniel Klein
    Replies:
    3
    Views:
    284
    Daniel Klein
    Nov 18, 2006
Loading...

Share This Page