Subject: Re: bug#23609: 25.0.92; Python eldoc freeze

From: Eli Zaretskii <[email-masked]>
Date: Fri, 27 May 2016 22:05:37 +0300

> From: Jules Tamagnan <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Fri, 27 May 2016 12:12:26 -0400
> 
> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
> index 5aeefe4..8f01ac9 100644
> --- a/lisp/progmodes/python.el
> +++ b/lisp/progmodes/python.el
> @@ -4293,12 +4293,18 @@ python-eldoc--get-doc-at-point
>          (unless (zerop (length docstring))
>            docstring)))))
>  
> +(defvar-local python-eldoc-get-doc t
> +  "If eldoc should be used to get the documentation automatically")
> +
>  (defun python-eldoc-function ()
>    "`eldoc-documentation-function' for Python.
>  For this to work as best as possible you should call
>  `python-shell-send-buffer' from time to time so context in
>  inferior Python process is updated properly."
> -  (python-eldoc--get-doc-at-point))
> +  (when python-eldoc-get-doc
> +    (with-timeout (1
> +                   (setq python-eldoc-get-doc nil))
> +      (python-eldoc--get-doc-at-point))))
>  
>  (defun python-eldoc-at-point (symbol)
>    "Get help on SYMBOL using `help'.
> 
> This patch adds the buffer local variable 'python-eldoc-get-doc which is
> intially set to t but if eldoc takes longer than one second to fetch the
> documentation then it will be set to nil. With the variable being nil,
> eldoc will no longer try to automatically fetch the documentation. The
> documentation can still be fetched with "C-cC-f". This avoids removing
> global-eldoc mode and allows the user to manually fetch the
> documentation while disabling the automatic fetching which causes the
> unexpected freezing. If the user calls eldoc themselves then it can
> still freeze but then thats their fault and they can press "C-g" to send
> a keyboard interupt to their process. At least it won't freeze
> spontaneously.

Thanks, this is now clear.  A coupe of comments:

  . Should 1 be a defcustom?  IOW, could it be that different users
    have different annoyance thresholds, and are willing to wait
    longer before turning eldoc-mode off?

  . The problem happens only when the interpreter is busy doing
    something, is that right?  If so, perhaps we shouldn't turn
    eldoc-mode off, but instead simply return?

  . If we do turn eldoc-mode off, then I think a message to that
    effect is in order, to let the user know.

Thanks for working on this.