Closed fratcn closed 2 years ago
Not able to replicate your error.
-*- mode: compilation; default-directory: "/tmp/" -*-
Comint started at Fri Dec 18 07:45:06
/home/lucius/.pyenv/shims/python test.py
Enter a temprature in Celsius:37
That's 98.6 degrees Fahrenheit
Inferior Python finished at Fri Dec 18 07:45:12
The trick is: The error happens when emacs start edit the code,after a while, the error may goes away and output the right answer,after a while,this python-running error comes back again. Really don't know why the spacemacs act like a unstable human. The spacemacs is installed clean from official github,and the python layer is added following the dotspacemancs instruction.
SPC m c C runs the command spacemacs/python-execute-file-focus, which is an
interactive Lisp function in ‘../../funcs.el’.
It is bound to <M-return> c C, M-m m c C, and many ordinary text characters.
(spacemacs/python-execute-file-focus ARG)
Execute a python script in a shell and switch to the shell buffer in
‘insert state’.
guess something wrong with the ‘interactive Lisp function in ‘../../funcs.el’’
Today I backup emacs.d and turn from master to delevop branch of Spacemacs,this error replicate again.
I find out the lisp code of “python-execute-file” in ~/.emacs.d/layers/+lang/python/funcs.el:
(defun spacemacs/python-execute-file (arg)
"Execute a python script in a shell."
(interactive "P")
;; set compile command to buffer-file-name
;; universal argument put compile buffer in comint mode
(let ((universal-argument t)
(compile-command (format "%s %s"
(spacemacs/pyenv-executable-find python-shell-interpreter)
(shell-quote-argument (file-name-nondirectory buffer-file-name)))))
(if arg
(call-interactively 'compile)
(compile compile-command t)
(with-current-buffer (get-buffer "*compilation*")
(inferior-python-mode)))))
(defun spacemacs/python-execute-file-focus (arg)
"Execute a python script in a shell and switch to the shell buffer in
`insert state'."
(interactive "P")
(spacemacs/python-execute-file arg)
(switch-to-buffer-other-window "*compilation*")
(end-of-buffer)
(evil-insert-state))
Anything wrong with it?
Since I'm not able to replicate the error, I cannot debug this.
python-execute-file
creates "compilation-mode" buffer, which looks like not playing well with an interactive input. Probably python-shell-send-buffer-switch
is more suitable for this case (, s B
)
python-shell-send-buffer-switch
work like this:
Python 3.9.1 (default, Dec 13 2020, 11:55:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: Enter a temprature in Celsius:-10
Out[4]: -10
In [5]: Enter a temprature in Celsius:25
Out[8]: 25
In [9]:
In [9]: Enter a temprature in Celsius:0
That's 32.0 degrees Fahrenheit
In [12]: Enter a temprature in Celsius:-10
Out[15]: -10
In [16]: Enter a temprature in Celsius:-10
Out[19]: -10
In [20]: Enter a temprature in Celsius:-10
Out[23]: -10
In [24]: Enter a temprature in Celsius:25
That's 77.0 degrees Fahrenheit
In [25]: Enter a temprature in Celsius:-10
Out[28]: -10
the output isn't right all the time,but is right just for twice.so this works like just like python-execute-file
Does disabling company-mode in either one (inferior buffer or compilation buffer) solve the problem?
Maybe you could try a clean configuration with just the Python layer.
well,it works when I clear the auto-completion layer. Thank you.
@fratcn emacs sends commands to get completions meanwhile you are typing the input, hence everything breaks. But I think you should not remove the layer, it should be enough to do M-x company-mode in the inferior buffer to make sure it is disabled only for this buffer.
@fratcn emacs sends commands to get completions meanwhile you are typing the input, hence everything breaks. ...
@alexey0308 How's this possible? Executing the current script should be instantaneous, and how is it possible to break it by keep typing?
@lebensterben the input command makes script waiting for the user input => user starts typing => completion query sent to the interpreter before user press "enter". You can see the error msg in the first post: can not convert "34\t\x08...", so additional string was sent after the user typed 34. But this is only a guess.
@lebensterben the input command makes script waiting for the user input => user starts typing => completion query sent to the interpreter before user press "enter". You can see the error msg in the first post: can not convert "34\t\x08...", so additional string was sent after the user typed 34. ...
@alexey0308 I also had tried to type input while the focus is not in the inferior shell, but I don't see this error. Have you replicated this?
But if you send the buffer to the inferior shell, you have to type the input within the inferior shell, I am confused now, how do you type "while the focus is not in the inferior shell"?
In my case, there is no error output for inferior buffer, same as here. If I enter fast, so completion's not started yet, I get the Fahrenheit. If I enter with some pause before pressing enter, no Fahrenheit in output.
But if you send the buffer to the inferior shell, you have to type the input within the inferior shell, I am confused now, ...
@alexey0308 I kept typing while the focus is not in inferior shell, and therefore nothing is actually input there. Once I switch to the inferior shell, auto-completion is not in effect, as it shouldn't be.
@lebensterben As I understand, with lsp-mode, completion in the file buffer comes from the lsp server, but in the inferior buffer from the inferior buffer process, hence they are independent and typing in the file buffer has no effect.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
Description :octocat:
Python run error, while tested ok with python and ipython outside the spacemacs.
Reproduction guide :beetle:
The python code:
Observed behaviour: :eyes: :broken_heart:
Expected behaviour: :heart: :smile:
System Info :computer:
Backtrace :paw_prints: