-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
LC_CTYPE=C: pydoc leaves terminal in an unusable state #65597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
$ ./python -m pydoc heapq Traceback (most recent call last):
File "/home/stefan/hg/cpython/Lib/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/home/stefan/hg/cpython/Lib/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/stefan/hg/cpython/Lib/pydoc.py", line 2615, in <module>
cli()
File "/home/stefan/hg/cpython/Lib/pydoc.py", line 2580, in cli
help.help(arg)
File "/home/stefan/hg/cpython/Lib/pydoc.py", line 1862, in help
elif request: doc(request, 'Help on %s:', output=self._output)
File "/home/stefan/hg/cpython/Lib/pydoc.py", line 1600, in doc
pager(render_doc(thing, title, forceload))
File "/home/stefan/hg/cpython/Lib/pydoc.py", line 1408, in pager
pager(text)
File "/home/stefan/hg/cpython/Lib/pydoc.py", line 1422, in <lambda>
return lambda text: pipepager(text, os.environ['PAGER'])
File "/home/stefan/hg/cpython/Lib/pydoc.py", line 1449, in pipepager
pipe.write(text)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe7' in position 3574: ordinal not in range(128) $ stty sane
$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C |
Works fine for me. |
the pydoc module works fine but when I use CTRL-C to quit it, I get this error in the terminal. I think it's an other bug but the traceback is really similar. Stephane Traceback (most recent call last):
File "/Users/stephane/src/projects/externals/cpython/Lib/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/Users/stephane/src/projects/externals/cpython/Lib/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/stephane/src/projects/externals/cpython/Lib/pydoc.py", line 2615, in <module>
cli()
File "/Users/stephane/src/projects/externals/cpython/Lib/pydoc.py", line 2580, in cli
help.help(arg)
File "/Users/stephane/src/projects/externals/cpython/Lib/pydoc.py", line 1862, in help
elif request: doc(request, 'Help on %s:', output=self._output)
File "/Users/stephane/src/projects/externals/cpython/Lib/pydoc.py", line 1600, in doc
pager(render_doc(thing, title, forceload))
File "/Users/stephane/src/projects/externals/cpython/Lib/pydoc.py", line 1408, in pager
pager(text)
File "/Users/stephane/src/projects/externals/cpython/Lib/pydoc.py", line 1428, in <lambda>
return lambda text: pipepager(text, 'less')
File "/Users/stephane/src/projects/externals/cpython/Lib/pydoc.py", line 1450, in pipepager
pipe.close()
File "/Users/stephane/src/projects/externals/cpython/Lib/os.py", line 957, in close
returncode = self._proc.wait()
File "/Users/stephane/src/projects/externals/cpython/Lib/subprocess.py", line 1581, in wait
(pid, sts) = self._try_wait(0)
File "/Users/stephane/src/projects/externals/cpython/Lib/subprocess.py", line 1529, in _try_wait
(pid, sts) = _eintr_retry_call(os.waitpid, self.pid, wait_flags)
File "/Users/stephane/src/projects/externals/cpython/Lib/subprocess.py", line 502, in _eintr_retry_call
return func(*args)
KeyboardInterrupt |
Did you use the same locale settings? |
|
Sorry, then I should have been more explicit: The failure only occurs |
Ah, yes, my lc_ctype was en_US.utf-8. I can reproduce it if I change that. |
I use OSX 10.9 on my laptop, Python 3.5 and I get this error in one case. If I use CTRL-C to quit the application and if LC_CTYPE=C. with the 'q' key, I don't get this problem. Just LC_CTYPE=C and CTRL-C and I have to reset my terminal. |
I can also confirm the need to reset the terminal when using So we have two issues then:
In Python2.7 neither of the issues is present. |
In python 2.7, If I use my working locales (utf-8) and I use CTRL-C, pydoc does not quit but leave a message when the screen is cleaned. same result with LC_CTYPE=C bash-4.3$ python -m pydoc heapq
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 2359, in <module>
if __name__ == '__main__': cli()
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 2328, in cli
help.help(arg)
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 1793, in help
elif request: doc(request, 'Help on %s:')
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 1532, in doc
pager(render_doc(thing, title, forceload))
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 1337, in pager
pager(text)
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 1357, in <lambda>
return lambda text: pipepager(text, 'less')
File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 1379, in pipepager
pipe.close()
KeyboardInterrupt
bash-4.3$ |
heapq documentation contains "François" which is not encodable to ASCII. When using LC_ALL=C, the locale encoding is ASCII (at least on Linux). It's not easy to specify a different error handler globally in pydoc, different functions are used and child processes are spawned. The subprocess module doesn't allow to specify an error handler different than strict (see bpo-6135). I propose pydoc_encoding.patch which escapes manually non-encodable characters. I chose sys.getfilesystemencoding(), I'm not sure that it's the encoding used for all cases of getpager() on all platforms. For example, on Windows, sys.getfilesystemencoding() is the ANSI code page, whereas sys.stdout.encoding is the OEM code page. |
"LC_CTYPE=C: pydoc leaves terminal in an unusable state" In the use case, pydoc doesn't touch the terminal, it's the pager: the program "less". I don't see how to ensure that the terminal state is restored, even on error. |
STINNER Victor <report@bugs.python.org> wrote:
Python2 suppresses the exception until after normal exit (pressing 'q'). In Python3 you can also get the unusable terminal by pressing Ctrl-C, |
The patch works well BTW. We can create another issue for the |
New changeset 89a29e92416f by Victor Stinner in branch '3.4': New changeset 3424d65ad5ce by Victor Stinner in branch 'default': |
I fixed the initial bug and so I close the issue. Open a new issue if you have an idea to restore the terminal state when the pager breaks the terminal. I don't think that it's possible to save/restore the terminal state in a portable way. |
The KeybaordInterrupt problem has been dealt with in bpo-23792. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: