I am using emacs 25.2.1
Look at the following simple code:
import sys
def yes_no_barrier(message):
print(message + ' (yes/no): ')
while 1:
s=str(input(message + ' (yes/no): '))
if s == 'yes':
return 'yes'
if s == 'no':
return 'no'
print('please enter yes or no')
yes_no_barrier('Are you tall?')
I tried to run the code in a real terminal (Python 3.6.4) and it was worked.
Then I tried to run it inside emacs, first using C-c C-p
for opening a Python console, and then, from the .py
buffer, pressing C-c C-c
.
I tried no
and the code worked, I then tried yes
and other strings and the Python buffer froze, forcing me to press C-g
. I have no clue what there is special with no
except for being shorter than the word yes
.
Since I was always getting the same strange behaviour I dug the web and I tried random stuff, finally solving the issue.
Here there is the full Python configuration which fixed the issue, not sure which part did it.
;I also installed from list-packages python-mode
(require 'python)
(add-hook 'python-mode-hook
(lambda ()
(setq indent-tabs-mode t)
(setq tab-width 4)
(setq python-indent 4)))
(setq scroll-down-aggressively 1)
(defun python-shell-parse-command ()
"Return the string used to execute the inferior Python process."
"/usr/bin/python3 -i")
(setq py-python-command "python3")
(setq py-shell-name "python3")
(setq python-shell-interpreter "python3")
I was happy with this magic code, but I had to switch to IPython (6.2.1, still using Python 3.6.4) since I wanted to solve this other problem, described here.
That problem was solved but now I have back the same problem with input()
which I described before: no
works but yes
makes the console freeze.
I tried the obvious modifications to my configuration, which are listed here:
(setenv "IPY_TEST_SIMPLE_PROMPT" "1") ;for fixing a problem with IPython not showing correctly
(setq python-shell-interpreter "/usr/local/bin/ipython"
python-shell-interpreter-args "--profile=dev -i")
(defun python-shell-parse-command () "/usr/local/bin/ipython
--profile=dev -i")
(setq py-python-command "ipython")
(setq py-shell-name "ipython")
(setq python-shell-interpreter "ipython")
But the error this time is not disappearing.
Can you help me, please? Does the code work in your emacs?
EDIT1:
I just realised that the problem does not arise when I press return but when I type the third letter of a word, so if I type yes
, then I will not be able to use the console anymore. For instance I will not be able to type backspace and I will be forced to press C-g
to send a keyboard interrupt and make the console usable again.
EDIT2:
I removed the line (require 'python)
and now I type M-x ipython
. The console that will appear works and I can send commands to it with C-c C-c
. The console that I open with C-c C-p
does not work. So I can consider solved my problem.
RET
(i.e.C-h k RET
and then instrument this function for debugging: gnu.org/software/emacs/manual/html_node/elisp/… then try to reproduce the buggy behavior and step through the code until you see what's causing to get stuck.