Bugs item #1736483, was opened at 2007-06-13 09:41 Message generated for change (Comment added) made by ilgiz You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1736483&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.3 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Eric (cpegeric) Assigned to: Nobody/Anonymous (nobody) Summary: os.popen('yes | echo hello') stuck Initial Comment: after calling os.popen('yes | echo hello'), the process never returns. ---------------------------------------------------------------------- Comment By: Ilguiz Latypov (ilgiz) Date: 2007-06-13 23:15 Message: Logged In: YES user_id=281701 Originator: NO It appears your "yes" does not catch SIGPIPE. I've reproduced the issue with $ python -c 'import sys, os; sys.stdout.write(os.popen("while :; do echo yes ; done | echo hello").read())' Traceback (most recent call last): File "<string>", line 1, in <module> KeyboardInterrupt The documentation on Python module signal says SIGPIPE is ignored by Python as well. My work-around to this was to catch SIGPIPE, but the GNU C library would terminate the whole script. $ python -c 'import sys, os, signal; signal.signal(signal.SIGPIPE, signal.SIG_DFL); sys.stdout.write(os.popen("while :; do echo yes ; done | echo hello").read())' hello http://www.gnu.org/software/libc/manual/html_node/Operation-Error-Signals.html Perhaps, writing own signal handler might help. ---------------------------------------------------------------------- Comment By: Eric (cpegeric) Date: 2007-06-13 22:46 Message: Logged In: YES user_id=1595194 Originator: YES sorry for the misunderstanding. Here is the result. % yes | echo hello hello % echo $? 0 % ---------------------------------------------------------------------- Comment By: Ilguiz Latypov (ilgiz) Date: 2007-06-13 22:24 Message: Logged In: YES user_id=281701 Originator: NO I've realized my suggestion was not precise. I meant asking to run the argument to popen() rather than popen(). That is, I would run this from command line to see if there is an issue with the shell: $ yes | echo hello ---------------------------------------------------------------------- Comment By: Eric (cpegeric) Date: 2007-06-13 21:28 Message: Logged In: YES user_id=1595194 Originator: YES command line also get stuck. The OS is MacOSX. Python version 2.3.5. Will it help update to new version? I quited the program by Ctrl-C. python -c 'import sys, os; sys.stdout.write(os.popen("yes | echo hello").read())' ^CTraceback (most recent call last): File "<string>", line 1, in ? KeyboardInterrupt % python -c 'import sys, os; sys.stdout.write(os.popen3("yes | echo hello")[1].read())' ^CTraceback (most recent call last): File "<string>", line 1, in ? KeyboardInterrupt ---------------------------------------------------------------------- Comment By: Ilguiz Latypov (ilgiz) Date: 2007-06-13 13:07 Message: Logged In: YES user_id=281701 Originator: NO Could you try the same command from your shell? I am guessing "yes" will write an error message about the broken pipe to stderr. $ python -c 'import sys, os; sys.stdout.write(os.popen("yes | echo hello").read())' yes: standard output: Broken pipe yes: write error hello $ python -c 'import sys, os; sys.stdout.write(os.popen3("yes | echo hello")[1].read())' hello ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1736483&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com