This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: getpass raises IOError when several returns are in stdin before getpass was called
Type: behavior Stage:
Components: IO, Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: avihu, gregory.p.smith
Priority: normal Keywords:

Created on 2009-11-01 16:46 by avihu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg94791 - (view) Author: Avihu Turzion (avihu) Date: 2009-11-01 16:46
When I have the following code:

blah.py
=======

import getpass
nothing = getpass.getpass("blah:")

And I run it like so:

>>> sleep 5
./blah.py <return>
<return>

(I write the ./blah.py and returns while the sleep occurs)

I get the following stack-trace:

Traceback (most recent call last):
  File "./xuy.py", line 5, in <module>
    nothing = getpass.getpass("XUY:")
  File "/usr/local/lib/python2.6/getpass.py", line 81, in unix_getpass
    stream.write('\n')
IOError: [Errno 29] Illegal seek
close failed in file object destructor:
IOError: [Errno 29] Illegal seek

This error occurs only when getpass is called with 2 or more returns in 
the buffer. One return will not reveal the problem.

Running this code with strace shows clearly that the seek problem is 
because that for return in the buffer it tries to seek back. 2 returns 
will cause it to seek -2. 7 returns will cause it to seek -7.

This problem was introduced in python 2.6, and is maintained throughout 
the minor releases of python 2.6 - 2.6.4. It doesn't appear in python 
2.5 and before, and it doesn't appear in python 3.

Doing sys.stdin.flush() doesn't resolve this issue.
msg94795 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-11-01 17:52
am unable to duplicate this behavior on Linux or OS X using python 2.6.

What platform did you see the problem on?

that said, can you apply the following patch to your getpass.py and see if 
it helps at all?

http://svn.python.org/view/python/trunk/Lib/getpass.py?
r1=74860&r2=76000&pathrev=76000
msg94796 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-11-01 17:54
ah i misread your example.  the following works to reproduce it:


Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time, getpass
>>> time.sleep(5)
getpass.getpass()  


>>> getpass.getpass()
Password: Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/getpass.py", line 81, in unix_getpass
    stream.write('\n')
IOError: [Errno 29] Illegal seek
msg94797 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-11-01 17:55
and the r76000 patch does not fix it.  investigating.
msg94798 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-11-01 18:31
change that.  it looks like r76000 in trunk already fixes this.  i was 
using an old build when i tried earlier.

merged into release26-maint in r76015.
msg94824 - (view) Author: Avihu Turzion (avihu) Date: 2009-11-02 10:21
Great. Thanks :)
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51495
2009-11-02 10:21:57avihusetmessages: + msg94824
2009-11-01 18:31:40gregory.p.smithsetstatus: open -> closed
resolution: fixed
messages: + msg94798
2009-11-01 17:55:01gregory.p.smithsetmessages: + msg94797
2009-11-01 17:54:03gregory.p.smithsetmessages: + msg94796
2009-11-01 17:52:54gregory.p.smithsetmessages: + msg94795
2009-11-01 17:47:05gregory.p.smithsetnosy: + gregory.p.smith
title: getpass crashes when several returns are in stdin before getpass was called -> getpass raises IOError when several returns are in stdin before getpass was called
priority: normal
assignee: gregory.p.smith
components: + Library (Lib)
type: crash -> behavior
2009-11-01 16:46:26avihucreate