Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32003
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <dwightdhutto@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'importing': 0.04; 'subject:Python': 0.05; 'sys': 0.05; '"__main__":': 0.07; '__name__': 0.07; 'except:': 0.07; 'raised': 0.07; 'try:': 0.07; 'python': 0.09; '"w")': 0.09; '2to3': 0.09; 'exits': 0.09; 'filename)': 0.09; 'ioerror': 0.09; 'ioerror:': 0.09; 'naturally': 0.09; 'oh,': 0.09; 'oserror': 0.09; 'received :mail-qc0-f174.google.com': 0.09; 'spawn': 0.09; 'subject:module': 0.09; 'through,': 0.09; 'worked,': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; ':-)': 0.13; '"about': 0.16; '(just': 0.16; '2.)': 0.16; '2.7.3': 0.16; '24,': 0.16; 'driscoll': 0.16; 'oct': 0.16; 'propagated': 0.16; 'pty': 0.16; 'py3': 0.16; 'record,': 0.16; 'relevant.': 0.16; 'sys.exit(1)': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'skip:p 30': 0.20; 'mostly': 0.20; 'import': 0.21; 'pipe': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'minutes.': 0.23; "i've": 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'url:bugs': 0.24; 'linux': 0.24; 'testing': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(which': 0.26; '(most': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'subject:/': 0.28; 'actual': 0.28; 'run': 0.28; 'parent': 0.29; 'though.': 0.29; "i'm": 0.29; 'that.': 0.30; 'worked': 0.30; 'writes': 0.30; 'error': 0.30; 'url:python': 0.32; 'file': 0.32; 'suggestion': 0.32; 'print': 0.32; 'curious': 0.33; 'rid': 0.33; 'traceback': 0.33; 'ubuntu': 0.33; 'problem': 0.33; 'anyone': 0.33; 'received:google.com': 0.34; 'returning': 0.35; 'open': 0.35; 'pm,': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'child': 0.36; "i'll": 0.36; 'test': 0.36; 'enough': 0.36; 'ok,': 0.37; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'easily': 0.39; 'little': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'further': 0.61; 'subject:, ': 0.61; 'first': 0.61; 'more': 0.63; 'enthusiastic': 0.65; 'subject:The': 0.71; 'sounds': 0.71; 'information:': 0.74; '100%': 0.76; 'dumb': 0.84; "it'd": 0.84; 'quits.': 0.84; 'sunshine': 0.84; 'reducing': 0.95 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=157mTa8aHd0Jm9S9R8fPvNhUzk4bOrd9Va7F5BC+ogc=; b=sWYhvIbXsPuUZtMHWINQ8aMt6AtXxXYvevv1dg5Cx2GnmeKTqXKzJOk8XwouQfUEjB F+uU3z9t4u5vhxhLSp8LiVW3fOM4KM5WegyzWoPBxjO98V3exoVV1XoPNgmy92bQIJV7 /8ubHgcIo/uK0qAYmwmCChYqtLMi/YG0122C5hYwhj2dxYtPTu9MKW/g35pkvQixu5P8 bzCSlpBK1VqxHbUnizERMISQJ40HXnF3+mnUNIrlGVf+lt0PfP6LeZA1CSPXUYJiJqIQ GxmuSixo6CV0ZVm5IIf70YsMy4zpzWxSoIYHKTcq5CNfUXTMxgZgqa6cwLWqmSVbW+wL 9M1Q== |
| MIME-Version | 1.0 |
| In-Reply-To | <50876356.3030005@wisc.edu> |
| References | <508759A9.7070601@wisc.edu> <50875A83.6030806@wisc.edu> <50876356.3030005@wisc.edu> |
| Date | Wed, 24 Oct 2012 02:02:08 -0400 |
| Subject | Re: The pty module, reading from a pty, and Python 2/3 |
| From | David Hutto <dwightdhutto@gmail.com> |
| To | Evan Driscoll <edriscoll@wisc.edu> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2726.1351058530.27098.python-list@python.org> (permalink) |
| Lines | 102 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351058530 news.xs4all.nl 6852 [2001:888:2000:d::a6]:56823 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32003 |
Show key headers only | View raw
On Tue, Oct 23, 2012 at 11:41 PM, Evan Driscoll <edriscoll@wisc.edu> wrote:
> OK, one more self-reply. :-)
>
> I found http://bugs.python.org/issue5380 which seems to be relevant. Sounds
> like the OS is returning an error, and that's naturally being propagated
> through Python. And further testing reveals the problem only surfaces when
> the child actually exits -- if the child writes data to the pipe and is more
> enthusiastic about living, then the parent can read it successfully. While
> it'd be nice if my example worked, for my actual purpose I think that's good
> enough (I just won't be able to test *quite* as easily for a while).
>
> I am still curious if anyone know why it worked in 2 though.
>
> Evan
>
>
>
>
> On 10/23/2012 10:03 PM, Evan Driscoll wrote:
>>
>> Oh, and a little more information:
>>
>> The log.txt file I create has the message that it's "about to execlp", and
>> the exec() *does* actually happen -- the IOError is raised after the child
>> process quits.
>>
>> Evan
>>
>>
>>
>> On 10/23/2012 09:59 PM, Evan Driscoll wrote:
>>>
>>> I have the following program. Everything is sunshine and rainbows when I
>>> run in in Python 2, but when I run it under Python 3 I get an IOError. 2to3
>>> only reports one dumb suggestion re. a print call (which I can get rid of by
>>> importing __future__'s print_function, and then it just suggests removing
>>> that import).
>>>
>>> Can anyone shed any light? I am on Ubuntu Linux with Python 2.7.3 and
>>> 3.2.3.
>>>
>>>
>>> (Just for the record, I figured out that it ran under Python 2 by
>>> accident as I was reducing it for a "why doesn't this run?" email. :-) I'm
>>> not super-familiar with Py3 as I've mostly only worked with 2.)
>>>
>>> I'm not 100% sure how this will come through, so I've also put it at
>>> http://pastebin.com/60wjXSF3.
>>>
>>> Evan
>>>
>>>
>>> import sys
>>> import pty
>>> import os
>>>
>>> def get_text(filename):
>>> try:
>>> ( child_pid, fd ) = pty.fork() # OK
>>> except OSError as e:
>>> print(str(e))
>>> sys.exit(1)
>>>
>>> if child_pid == 0:
>>> try:
>>> with open("log.txt", "w") as f:
>>> f.write("about to execlp")
>>> os.execlp("cat", "cat", filename)
>>> except:
>>> with open("log.txt", "w") as f:
>>> f.write("could not spawn process")
>>> print("Could not spawn")
>>> sys.exit(1)
>>>
>>> child_pty = os.fdopen(fd)
>>> return child_pty.read()
>>>
>>>
>>> if __name__ == "__main__":
>>> print(get_text("my-pty-test.py"))
>>>
>>>
>>> The read error I get is
>>>
>>> Traceback (most recent call last):
>>> File "my-pty-test.py", line 28, in <module>
>>> print(get_text("my-pty-test.py"))
>>> File "my-pty-test.py", line 24, in get_text
>>> return child_pty.read()
>>> IOError: [Errno 5] Input/output error
at first glance, you have the file open for writing('w'), not
reading('r'), but may not be that.
I'll check if I get a few minutes.
--
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: The pty module, reading from a pty, and Python 2/3 David Hutto <dwightdhutto@gmail.com> - 2012-10-24 02:02 -0400
csiph-web