Issue1787

classification
Title: getpass.getpass() hangs when running on Windows
Type: behaviour Severity: major
Components: Library Versions: Jython 2.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, irmen, jackgene, samwyse, zyasoft
Priority: normal Keywords:

Created on 2011-08-09.21:06:28 by jackgene, last changed 2014-06-25.16:05:06 by zyasoft.

Files
File name Uploaded Description Edit Remove
getpass.py jackgene, 2011-08-09.21:06:27 Updated getpass.py
Messages
msg6598 (view) Author: Jack Leow (jackgene) Date: 2011-08-09.21:06:27
Hi, 
I've run into a problem where on Windows, the getpass.getpass() function does not behave as expected. I'm expecting it to: 
1. Prompt me for a password. 
2. Wait for me to type something in (without echoing), and press enter. 
3. Return the string I typed. 

However, the behavior I observe is that after the password prompt, the program hangs: 

Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) 
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_26 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from getpass import getpass 
>>> getpass() 
Password: 

(and this point, the program hangs, and does not respond to keyboard input, not even Ctrl-C, Ctrl-D, Ctrl-Z etc) 

I've successfully replicated this behavior on Windows Vista, Windows Server 2003, and Windows Server 2008. Solaris, MacOS X and Linux does not appear to be affected. 

I've implemented the attached workaround in my environment, and it seems to work (though it's more Java than Jython).
msg6657 (view) Author: (samwyse) Date: 2011-09-28.21:27:13
I have the same problem on Windows XP Professional, Service Pack 3, running the same version of Jython on the same version of Java.
msg6712 (view) Author: Irmen de Jong (irmen) Date: 2011-11-06.23:27:26
Actually the problem is not getpass itself, but sys.stdin.readline.

If you type this in a jython prompt it will hang the same way:

import sys; sys.stdin.readline()


Digging a bit further it seems there are some bugs in TextIOWrapper.read().   It looks for '\r' and '\n' characters but it appears that reading from the console through that underlying readahead buffer gives different characters for Enter (returns CR instead of LF), EOF (ctrl-Z, returns char code 26), and it even swallows CTRL-C as a 'normal' character with code 3 (ETX) and CTRL-D as 4 (EOT). This screws up the handling of the characters and the loop never exits.

I don't have any experience with java nio to tell what's going on here.
msg8710 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.05:17:20
Not currently a problem for 2.7 when running on Windows 8.1. I believe Windows 7 is likely the earliest version we will be supporting.

Please respond if this is still an issue.
History
Date User Action Args
2014-06-25 16:05:06zyasoftsetstatus: pending -> closed
2014-06-19 05:17:20zyasoftsetstatus: open -> pending
resolution: out of date
messages: + msg8710
nosy: + zyasoft
2013-02-25 19:29:24fwierzbickisetpriority: normal
nosy: + fwierzbicki
versions: + Jython 2.5, - 2.5.2
2011-11-06 23:27:26irmensetnosy: + irmen
messages: + msg6712
2011-09-28 21:27:13samwysesetnosy: + samwyse
messages: + msg6657
2011-08-09 21:06:28jackgenecreate