New submission from sping:

Hi!


A college of mine ran into a bug with raw_input.
We have a shell derived from stdlib module "cmd" here but the bug shows
with plain raw_input, as well (see demo code).

For the symptoms: the shell is executing commands from history that the
user explicitly chose not to run.  Since our shell does things like
deallocation of LVM volumes, that behavior is rather troublesome :)

How does it happen?

 * When pressing Ctrl+R, an incremental reverse history search is started.
   During that search, you normalled press Escape/Ctrl+J/Ctrl+G to end
   search or Return to pick a result.

 * When you press Ctrl+C though, the next call to the raw_input function
   believes to be in search mode still (while not showing "(reverse-i-search)"
   or indicating search some way).

 * Now when (entering some text and) pressing return now, the string last
   shown during incremental search is being return from raw_input
   (and executed in context of the cmd module).

I have re-produced the issue with Python 2.7.3, 2.7.9, 3.2.3, 3.4.2.

For a workaround, one can handle KeyboardInterrupt and internal adjust
variable rl_readline_state of the C readline library.
I'm attaching (a minimal bug demo and) the ctypes based workaround that
works well over here.
(The workaround demo also shows that readline state is not fully reset
when Ctrl+C was pressed outside of search mode, since flag RL_STATE_DONE
is not set after.)

It would rock the house if this could be fixed in Python.

I'm looking forward to your reply.

Best,



Sebastian

----------
components: Interpreter Core
files: raw_input__workaround_demo.py
messages: 243828
nosy: sping
priority: normal
severity: normal
status: open
title: raw_input function (with readline): Ctrl+C (during search mode but not 
only) leaves readline in broken state
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file39467/raw_input__workaround_demo.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24266>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to