Issue1433

classification
Title: Can't flush output to pipes like Python can
Type: behaviour Severity: major
Components: Core Versions: 2.5.0
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, danny, fwierzbicki
Priority: Keywords:

Created on 2009-08-13.23:45:36 by danny, last changed 2009-08-25.08:02:01 by cgroves.

Files
File name Uploaded Description Edit Remove
unnamed danny, 2009-08-17.21:54:16
Messages
msg5023 (view) Author: Danny Goodman (danny) Date: 2009-08-13.23:45:35
In Jython, it doesn't seem be possible to flush the buffer of a
'write'-mode pipe on request the way Python does (pipe.flush() has no
effect).

At bottom is a simple program to create a pipe, write to it, read from
it, and close.  The behavior in Python is as expected: 

$ python post.py 
Read this line from child: "Read this line from parent: 'Test line'"
Waiting 10 seconds
Exiting


In Jython, though, the program hangs until quit forcibly:

$ jython post.py
Traceback (most recent call last):
  File "/usr/local/sem/CampaignManager/src/test/Pipes/post.py", line 6, in ?
    line = sys.stdin.readline()[:-1]
KeyboardInterrupt


If I close the pipe, instead of just flushing, though, the behavior is
correct, which leads me to think that 'flush()' is being ignored.  This
is important for being able to use pipes.

Cheers,
Danny



import os
import sys
import time

if len(sys.argv) > 1: # Child
    line = sys.stdin.readline()[:-1]
    sys.stdout.write("Read this line from parent: '%s'" %line)
    sys.stdout.flush()
else:
    pin,pout = os.popen2('/usr/bin/jython
/usr/local/sem/CampaignManager/src/test/Pipes/post.py --child')
    pin.write("Test line\n")
    pin.flush()
    #pin.close()
    print 'Read this line from child: "%s"' %pout.readline()
    print "Waiting 10 seconds"
    time.sleep(10)
    print "Exiting"
msg5052 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2009-08-17.21:32:52
What operating system are you on?  On my local OSX I seem to get the
same behavior from python and jython.
msg5053 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2009-08-17.21:38:51
oops, scratch that, I failed to port the script over to my system well
enough.  I was able to reproduce the hang.
msg5054 (view) Author: Danny Goodman (danny) Date: 2009-08-17.21:54:16
Thanks Frank.  FYI here's my os info in case it's helpful:
Linux yoda 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64
x86_64 GNU/Linux

On Mon, Aug 17, 2009 at 2:38 PM, Frank Wierzbicki <report@bugs.jython.org>wrote:

>
> Frank Wierzbicki <fwierzbicki@users.sourceforge.net> added the comment:
>
> oops, scratch that, I failed to port the script over to my system well
> enough.  I was able to reproduce the hang.
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue1433>
> _______________________________________
>
msg5064 (view) Author: Charlie Groves (cgroves) Date: 2009-08-25.08:02:00
Should be fixed as of r6718.  Thanks for the report!
History
Date User Action Args
2009-08-25 08:02:01cgrovessetstatus: open -> closed
resolution: fixed
messages: + msg5064
nosy: + cgroves
2009-08-17 21:54:17dannysetfiles: + unnamed
messages: + msg5054
2009-08-17 21:38:51fwierzbickisetmessages: + msg5053
2009-08-17 21:32:52fwierzbickisetnosy: + fwierzbicki
messages: + msg5052
2009-08-13 23:45:36dannycreate