jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 260 forks source link

Duplicate output in Jupyter console when calling external executables using the subprocess module #2042

Open bastro3000 opened 7 months ago

bastro3000 commented 7 months ago

Summary

Duplicate output in Jupyter console when calling external executables using the subprocess module

Steps to reproduce

  1. Open Emacs (GUI or Console mode)
  2. Open any .py file to enter Elpy mode
  3. Make sure the python shell interpreter is set to Jupyter (see Elpy configuration)
  4. Open an Elpy console window (C-x C-z)
  5. Execute the following Python code from the Elpy console window:
    import subprocess
    subprocess.call('/bin/pwd')

    Result: The current working directory is printed twice in the console.

The same happens with the standard output of any executable and if a call to subprocess.call is done while executing any python code from Emacs (e.g. using C-c C-c).

This doesn't occur when using the standard Python console.

My configuration

OS

Ubuntu Release 23.10 (Mantic Minotaur) 64-bit Kernel Linux 6.5.0-28-generic x86_64 MATE 1.26.2

Result of (elpy-config)

Elpy Configuration

Emacs.............: 29.3
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: jupyter ... (/home/sebastien/anaconda3/bin/jupyter)
RPC virtualenv....: rpc-venv (/home/sebastien/.emacs.d/elpy/rpc-venv)
 Python...........: python 3.10.13 (/home/sebastien/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: 0.19.1
 Autopep8.........: 2.0.4 (2.1.0 available)
 Yapf.............: 0.40.2
 Black............: 23.11.0 (24.4.0 available)
Syntax checker....: flake8 (/home/sebastien/anaconda3/bin/flake8)

Elpy configuration in my init.el

;; Enable elpy
(elpy-enable)

;; Use IPython for REPL
(setq python-shell-interpreter "jupyter"
      python-shell-interpreter-args "console --simple-prompt"
      python-shell-prompt-detect-failure-warning nil)
(add-to-list
 'python-shell-completion-native-disabled-interpreters
 "jupyter")

;; Enable flycheck
(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))

;; Disable mypy
(add-hook
 'elpy-mode-hook
 (lambda ()
   (add-to-list
    'flycheck-disabled-checkers
    'python-mypy)))

;; Enable autopep8
(require 'py-autopep8)
(add-hook 'elpy-mode-hook 'py-autopep8-mode)

;; Don't print code sent to ipython
(setq elpy-shell-echo-input nil)