Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what does "lost sys.stdin" error mean?

2,666 views
Skip to first unread message

lynvie

unread,
Jun 11, 2009, 5:50:32 PM6/11/09
to
I have a very simple program from the first chapter of a book on
python 3 (I'm a novice). I called the program tmp.py and the data
input file is sum.dat (just a list of numbers, 1 per line). When I
type into my command shell "tmp.py < sum.dat" I get an error from
"line=input()" -- that's line 7 from the code below. The exact error
message is:
RuntimeError: input(): lost sys.stdin.

print("Type integers, each followed by Enter; or ^D or ^Z to finish")
total=0
count=0

while True:
try:
line=input()
if line:
number=int(line)
total += number
count += 1
print("number =",number)
except ValueError as err:
print(err)
continue
except EOFError:
break

if count:
print("count =", count, "total =", total, "mean =", total/
count)

Tim Harig

unread,
Jun 11, 2009, 7:01:16 PM6/11/09
to
On 2009-06-11, lynvie <lyndi...@gmail.com> wrote:
> I have a very simple program from the first chapter of a book on
> python 3 (I'm a novice). I called the program tmp.py and the data
> input file is sum.dat (just a list of numbers, 1 per line). When I
> type into my command shell "tmp.py < sum.dat" I get an error from

What OS are you using? I know that pipes cause issues when working with
interpreters on Windows. You must call the python interpreter directly or
it will not be able to handle the pipe directly. I don't remember exacly
how the issue manifests but I remember it has bitten me before on Win32. I
don't currenlty have a Windows machine to test on.

> "line=input()" -- that's line 7 from the code below. The exact error
> message is:
> RuntimeError: input(): lost sys.stdin.

I am working on Linux and I have been unable to produce your error. My
Python version identifies itself as:

>>> import sys
>>> sys.version
'3.0.1 (r301:69556, Mar 17 2009, 11:42:03) \n[GCC 4.1.2]'

This is what I have done using your same tmp.py file as pasted from
a shell session:

17:52,505$ count=0

17:53,506$ while [ $count -lt 20 ]; do
echo $RANDOM >> sum.dat;
newcount=`echo "$count + 1" | bc`;
count=$newcount;
done

17:53,507$ python3.0 tmp.py < sum.dat


Type integers, each followed by Enter; or ^D or ^Z to finish

number = 22657
count = 1 total = 22657 mean = 22657.0
number = 12223
count = 2 total = 34880 mean = 17440.0
number = 10250
count = 3 total = 45130 mean = 15043.3333333
number = 20919
count = 4 total = 66049 mean = 16512.25
number = 20995
count = 5 total = 87044 mean = 17408.8
number = 28988
count = 6 total = 116032 mean = 19338.6666667
number = 13015
count = 7 total = 129047 mean = 18435.2857143
number = 25701
count = 8 total = 154748 mean = 19343.5
number = 6566
count = 9 total = 161314 mean = 17923.7777778
number = 19396
count = 10 total = 180710 mean = 18071.0
number = 16771
count = 11 total = 197481 mean = 17952.8181818
number = 2039
count = 12 total = 199520 mean = 16626.6666667
number = 655
count = 13 total = 200175 mean = 15398.0769231
number = 27417
count = 14 total = 227592 mean = 16256.5714286
number = 5000
count = 15 total = 232592 mean = 15506.1333333
number = 12015
count = 16 total = 244607 mean = 15287.9375
number = 8746
count = 17 total = 253353 mean = 14903.1176471
number = 29487
count = 18 total = 282840 mean = 15713.3333333
number = 3194
count = 19 total = 286034 mean = 15054.4210526
number = 8225
count = 20 total = 294259 mean = 14712.95

As you can see, it seems to be working as prescribed.

Tim Harig

unread,
Jun 11, 2009, 7:25:08 PM6/11/09
to
On 2009-06-11, Tim Harig <use...@ilthio.net> wrote:
> On 2009-06-11, lynvie <lyndi...@gmail.com> wrote:
>> I have a very simple program from the first chapter of a book on
>> python 3 (I'm a novice). I called the program tmp.py and the data
>> input file is sum.dat (just a list of numbers, 1 per line). When I
>> type into my command shell "tmp.py < sum.dat" I get an error from
> What OS are you using? I know that pipes cause issues when working with
> interpreters on Windows. You must call the python interpreter directly or
> it will not be able to handle the pipe directly. I don't remember exacly
> how the issue manifests but I remember it has bitten me before on Win32. I
> don't currenlty have a Windows machine to test on.

More info:
http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/10d3928277319bef

lynvie

unread,
Jun 12, 2009, 2:15:04 AM6/12/09
to

Thanks for the additional info! I had no idea this was an old Windows
problem... I'm using Windows XP and I'm up-to-date on all my patches.

The good news is I can invoke the script correctly now, thanks to your
help!

On Jun 11, 4:25 pm, Tim Harig <user...@ilthio.net> wrote:
> On 2009-06-11, Tim Harig <user...@ilthio.net> wrote:


>
> > On 2009-06-11, lynvie <lyndiech...@gmail.com> wrote:
> >> I have a very simple program from the first chapter of a book on
> >> python 3 (I'm a novice). I called the program tmp.py and the data
> >> input file is sum.dat (just a list of numbers, 1 per line). When I
> >> type into my command shell "tmp.py < sum.dat" I get an error from
> > What OS are you using?  I know that pipes cause issues when working with
> > interpreters on Windows.  You must call the python interpreter directly or
> > it will not be able to handle the pipe directly.  I don't remember exacly
> > how the issue manifests but I remember it has bitten me before on Win32.  I
> > don't currenlty have a Windows machine to test on.
>

> More info:http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/1...

Tim Harig

unread,
Jun 12, 2009, 4:01:44 AM6/12/09
to
On 2009-06-12, lynvie <lyndi...@gmail.com> wrote:
> Thanks for the additional info! I had no idea this was an old Windows
> problem... I'm using Windows XP and I'm up-to-date on all my patches.

s/problem/feature/
Steve Ballmer, CEO of Microsoft, would prefer that you think of it as a
'feature'.

This is a problem that I would suspect has plagued a lot of people because
it doesn't seem to be overly documented in any of the popular python
learning materials. Even Mark Hammond & Andy Robinson's book _Python
Programming on Win32_ doesn't mention the problem directly in its Windowes
gotchas section-- though it does mention there are a number of bugs in the
Windows implementation of popen().

> The good news is I can invoke the script correctly now, thanks to your
> help!

Happy Pythoning!

0 new messages