Subject: bug#20580: 25.0.50; python-shell-completion-complete-or-indent hangs emacs with ipython v 3.1.0

From: [email-masked] (Andreas Tjärnberg)
Date: Fri, 15 May 2015 00:13:11 +0200

Hi,

Short description:
When activating python with the ipython shell interpreter version 3.1.0
(latest) inside a virtual environment, TAB completion both in the
(run-python) shell and in a python file buffer hangs emacs.
I have to C-g to get back to the cursor.

Long description:
I use el-get to fetch the pyvenv package.
recipe to duplicate starting with:

$ emacs -q -l setup.el

8< cut here -------- setup.el -------- begin

(setq emacs-init-dir
      (file-name-directory (or load-file-name (buffer-file-name))))

(setq el-get-dir (expand-file-name "el-get" emacs-init-dir))
(add-to-list 'load-path (concat emacs-init-dir "el-get/el-get"))

(unless (require 'el-get nil 'noerror)
  (with-current-buffer
      (url-retrieve-synchronously
       "https://raw.github.com/dimitri/el-get/master/el-get-install.el")
    (let (el-get-master-branch)
      (goto-char (point-max))
      (eval-print-last-sexp))))

(add-to-list 'el-get-recipe-path (concat emacs-init-dir "recipes"))

(el-get 'sync '(pyvenv))

(setq
   python-shell-interpreter "ipython"
   python-shell-interpreter-args "--no-confirm-exit --no-banner"
   python-shell-prompt-regexp "In \\[[0-9]+\\]: "
   python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: ")

8< cut here -------------------------- end

now I proceed to create a virtual environment for python in the terminal
$ mkvirtualenv ipython_hangs_emacs

and install ipython with:
$ pip install ipython

Inside emacs I now use pyvenv-workon to work in this virtual environment.
and do
M-x run-python

Here is where the trouble start. The command hangs emacs but still
launches a *Python* shell buffer. C-g will give back control to me.

Now switching to the *Python* buffer and pressing TAB will hang emacs
until I C-g.

Running the code from the command
(message python-shell-completion-setup-code)
directly in the python shell
will complete without error, and I can call the function
';'.join(__PYTHON_EL_get_completions('''%s'''))
from the variable (python-shell-completion-module-string-code),
typed in to the python buffer with %s changed to something like "from sy"
will return a string with completions.

If I just run the above with the ipython version got from apt-get in Ubuntu,
everything works as expected but switching to an environment and
pip installing ipython doesn't.

The TAB key is mapped to (python-shell-completion-complete-or-indent)
but the code for completion seems to work,
however the help "C-h f" buffer does not suggest a file of origin for
this function so I
couldn't go further and doubt it would have helped any way becouse my
elisp knowledge only stretch so far.
But I assume, based on this, that the issue is there somewhere. 

Thank you for your help.

Regards
Andreas
-------------------------------------------------------------------------

In GNU Emacs 25.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.8)
 of 2015-05-08 on lgw01-14
Windowing system distributor `The X.Org Foundation', version 11.0.11501000
System Description:	Ubuntu 14.04.2 LTS

Configured using:
 `configure --build=x86_64-linux-gnu --prefix=/usr
 '--includedir=${prefix}/include' '--mandir=${prefix}/share/man'
 '--infodir=${prefix}/share/info' --sysconfdir=/etc --localstatedir=/var
 '--libdir=${prefix}/lib/x86_64-linux-gnu'
 '--libexecdir=${prefix}/lib/x86_64-linux-gnu' --disable-maintainer-mode
 --disable-dependency-tracking --prefix=/usr --sharedstatedir=/var/lib
 --program-suffix=-snapshot --with-x=yes --with-x-toolkit=gtk3
 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
 -Werror=format-security' CPPFLAGS=-D_FORTIFY_SOURCE=2
 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB

Important settings:
  value of $LC_MONETARY: sv_SE.UTF-8
  value of $LC_NUMERIC: sv_SE.UTF-8
  value of $LC_TIME: sv_SE.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t

Recent messages:
Mark set
Mark saved where search started
Mark set [2 times]
Mark deactivated
Auto-saving...done
previous-line: Beginning of buffer [9 times]
Mark set [3 times]
Mark deactivated
Mark set [2 times]
Mark deactivated

Load-path shadows:
/usr/share/emacs/site-lisp/dictionaries-common/flyspell hides /usr/share/emacs/25.0.50/lisp/textmodes/flyspell
/usr/share/emacs/site-lisp/dictionaries-common/ispell hides /usr/share/emacs/25.0.50/lisp/textmodes/ispell

Features:
(misearch multi-isearch shadow sort mail-extr emacsbug message
format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mailabbrev
gmm-utils mailheader sendmail eieio-opt speedbar sb-image ezimage dframe
find-func python debug pyvenv json easy-mmode .loaddefs compile comint
ansi-color ring el-get el-get-autoloading el-get-list-packages
el-get-dependencies el-get-build el-get-status pp el-get-methods
el-get-fossil el-get-svn el-get-pacman el-get-github-zip
el-get-github-tar el-get-http-zip el-get-http-tar el-get-hg el-get-go
el-get-git-svn el-get-fink el-get-emacswiki el-get-http el-get-notify
help-mode easymenu el-get-emacsmirror el-get-github el-get-git
el-get-elpa package epg-config el-get-darcs el-get-cvs el-get-bzr
el-get-brew el-get-builtin el-get-apt-get el-get-recipes derived
el-get-byte-compile el-get-custom el-get-core autoload lisp-mnt cl dired
mail-utils timezone parse-time gnutls network-stream nsm starttls
url-http tls mail-parse rfc2231 rfc2047 rfc2045 ietf-drums url-gw
url-cache url-auth url url-proxy url-privacy url-expand url-methods
url-history url-cookie url-domsuf url-util url-parse auth-source cl-macs
eieio eieio-core cl-generic byte-opt gv bytecomp byte-compile cl-extra
seq cconv cl-loaddefs pcase cl-lib gnus-util mm-util help-fns mail-prsvr
password-cache url-vars mailcap mule-util time-date tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 150050 17509)
 (symbols 48 24372 19)
 (miscs 40 574 382)
 (strings 32 32667 4967)
 (string-bytes 1 933676)
 (vectors 16 16961)
 (vector-slots 8 469120 10313)
 (floats 8 173 500)
 (intervals 56 450 156)
 (buffers 976 23)
 (heap 1024 29754 7019))