jorgenschaefer/elpy

Emacs/Elpy freezes on open string

Opened this issue · 3 comments

Summary

When I enter a string, starting with a single quote, under some circumstances, this will freeze Emacs, presumably because Elpy freezes or otherwise stalls.

At that point, I can exit emacs with C-g C-g (running in non-window mode), then kill the current process (i.e., emacs) from the command line, but nothing otherwise afaict. Since this is not the normal way to suspend or stop Emacs, I assume it's a running background process that causes Emacs to hang.

Steps to reproduce

I've managed to trace it to the following minimal Python code to open in Emacs:

def main():

    text = """Text"""
    f()
    g('')

Now, typing a single quote, ', on the empty line above text = ..., at the same indentation, and waiting a second, will cause Emacs to freeze. One way to prevent this seems to be to type '' quickly enough that Elpy doesn't kick in, then fill in the actual string contents. Also, a single double opening quote doesn't cause this either.

I do seem to need the lines with the triple quotes, single function call, and function call with the empty string.

My configuration & OS

I'm running Emacs on macOS 13.0.1, through a Homebrew installation, in iTerm (same issue in Terminal, not surprisingly).
My Python interpreter is installed with PyEnv; no idea how relevant this is.

I have tried this on Ubuntu 22.04 as well, but there is no problem there. So it seems to be related to macOS or my specific setup there.

I have seen a few possibly related, but older issues, on freezes (one specifically Macos related), but I can't tell whether that amounts to the same thing. I'm unfortunately too unfamiliar with Emacs and the Emacs package eco-system to be able to debug this further.

Result of (elpy-config)

Emacs.............: 28.2
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python3 3.8.14 (/Users/evert/.pyenv/shims/python3)
RPC virtualenv....: rpc-venv (/Users/evert/.emacs.d/elpy/rpc-venv)
 Python...........: python 3.8.14 (/Users/evert/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: Not found (0.18.2 available)
 Rope.............: Not found (1.5.1 available)
 Autopep8.........: Not found (2.0.0 available)
 Yapf.............: Not found (0.32.0 available)
 Black............: Not found (22.10.0 available)
Syntax checker....: flake8 (/Users/evert/.pyenv/shims/flake8)

Elpy configuration in my init.el

This is the full, minimal, init.el that I need to reproducce this problem.

(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/"))
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages '(elpy)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(package-initialize)
(elpy-enable)
yitang commented

encountered this same problems many times in the last few weeks in both macOS and Debian.

ioah86 commented

Same here for me. My config:

Emacs.............: 28.2
Elpy..............: Not found (Python), 1.35.0 (Emacs Lisp)
Virtualenv........: None
Interactive Python: python3 3.10.9 (/usr/bin/python3)
RPC virtualenv....: rpc-venv (/home/aheinle/.emacs.d/elpy/rpc-venv)
 Python...........: python nil (/home/aheinle/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: Not found
 Rope.............: Not found
 Autopep8.........: Not found
 Yapf.............: Not found
 Black............: Not found
Syntax checker....: Not found (flake8)

I also run into this a lot, and I just enabled toggle-debug-on-quit and hammered C-g, which gave me the following stack trace:

Debugger entered--Lisp error: (quit)
  re-search-forward("\\s|" nil t)
  python-nav-end-of-statement()
  python-nav-end-of-defun()
  python-info-current-defun()
  run-hook-with-args-until-success(python-info-current-defun)
  which-function()
  which-func-update-1(#<window 9 on dtw.py>)
  which-func-update()
  apply(which-func-update nil)
  timer-event-handler([t 0 0 500000 t which-func-update nil idle 0 nil])

The python- functions are from python.el, so this might actually be a bug from there?

EDIT: Yes, there's a bug report on the mailing list here

EDIT2: There's another very similar bug which is apparently fixed in emacs 29, so we might just have to wait for that to be released.