emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Emacs hangs while loading org file with python blocks
@ 2016-12-07  1:41 David Dynerman
  2016-12-07  3:41 ` Clément Pit--Claudel
  2016-12-07 13:41 ` Alan Schmitt
  0 siblings, 2 replies; 4+ messages in thread
From: David Dynerman @ 2016-12-07  1:41 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3504 bytes --]

Dear list,

For several months I've been encountering a frustrating bug. My emacs hangs while initially loading an org file with ~3000 lines and around two dozen python blocks. If I press C-g during the lockup, emacs wakes up and the file is loaded. The hang does not re-occur after happening on initial load - the bug will reoccur only if I restart emacs and load the file again. The hang seems to be related to fontifying the python blocks: after I abort with C-g, some blocks will be unfontified. 

I previously emailed the list about this bug (Wed, 17 Aug 2016, subject 'Emacs hangs while loading .org file'), but didn't have an easy way to reproduce the problem.

I've now managed to extract a minimal org file that reproduces the hang:

#+BEGIN_SRC python
  """xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"""
#+END_SRC
#+BEGIN_SRC python
  class x:  
      def x(self):
          """
	  """
          pass
#+END_SRC

To reproduce:

1) Save above as bug.org
2) Open a fresh emacs process, and C-x f bug.org <RET>
3) Observe emacs is unresponsive. I've let it run as long as 30 mins without any change. 

I am able to reproduce with emacs -Q, only executing the following in *scratch*:

(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/org") ;; org from git installed here
(require 'org)

This is with the latest org code from git (release_9.0-132-gd65aa3). The bug does NOT occur with org 8.2.10. I've been encountering this bug for several months, but unfortunately I don't remember exactly when I first saw it.

I'm running GNU Emacs 25.1.1 (x86_64-apple-darwin15.6.0, Carbon Version 157 AppKit 1404.47) of 2016-11-24.

I'm mystified as to what's going on here. It seems that removing any of the python code in the example above causes the bug to disappear, but I have no clue what the problem might be.

I've attached a profiler report captured during the hang. Here is the relevant part:

           - org-src-font-lock-fontify-block                    17419  46%
            - org-font-lock-ensure                              17240  45%
             - #<compiled 0x41086c73>                           17240  45%
              - font-lock-default-fontify-buffer                17240  45%
               - font-lock-fontify-region                       17240  45%
                - font-lock-default-fontify-region              17240  45%
                 - font-lock-fontify-syntactically-region              17240  45%
                  - python-font-lock-syntactic-face-function              17240  45%
                   - python-info-docstring-p                    17240  45%
                    - python-nav-backward-sexp                  17240  45%
                     - python-nav-forward-sexp                  17240  45%
                      - python-nav--forward-sexp                17240  45%
                       - python-info-end-of-block-p              17240  45%
                        - python-info-end-of-statement-p              17240  45%
                         - python-nav-end-of-statement              15444  41%
                            syntax-ppss                          8641  22%

It looks like emacs is getting stuck navigating the python blocks during fontification. The last org-mode call appears to be (org-font-lock-ensure).

If anyone has any suggestions on how to fix this, I'd be very interested to hearthem - I'm working with larger and larger org files containing python code, so I'm encountering this bug frequently.

Thank you very much,
David


[-- Attachment #2: fontify-bug-profile --]
[-- Type: application/octet-stream, Size: 300 bytes --]

+ ...                                                           19562  51%
+ redisplay_internal (C function)                               17420  46%
+ command-execute                                                 658   1%
+ timer-event-handler                                               9   0%

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Emacs hangs while loading org file with python blocks
  2016-12-07  1:41 Emacs hangs while loading org file with python blocks David Dynerman
@ 2016-12-07  3:41 ` Clément Pit--Claudel
  2016-12-07 13:41 ` Alan Schmitt
  1 sibling, 0 replies; 4+ messages in thread
From: Clément Pit--Claudel @ 2016-12-07  3:41 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 5260 bytes --]

Hi David,

It might be good to open a bug report on the Emacs side; a Python font-locking freeze was fixed on master recently, but there may be other ones (your example hangs Emacs for me too), and your profile doesn't seem very Org-specific.

The following backtrace might be useful too:

Debugger entered--Lisp error: (quit)
  python-nav-end-of-statement()
  python-info-end-of-statement-p()
  python-info-end-of-block-p()
  python-nav--forward-sexp(-1 nil nil)
  python-nav-forward-sexp(-1 nil nil)
  python-nav-backward-sexp()
  python-info-docstring-p((0 nil 24 34 nil nil 0 nil 42 nil nil))
  python-font-lock-syntactic-face-function((0 nil 24 34 nil nil 0 nil 42 nil nil))
  font-lock-fontify-syntactically-region(1 72 nil)
  font-lock-default-fontify-region(1 72 nil)
  font-lock-fontify-region(1 72 nil)
  font-lock-default-fontify-buffer()
  #[(_beg _end) … [font-lock-fontified font-lock-mode font-lock-default-fontify-buffer nil] 2](1 72)
  org-font-lock-ensure()
  org-src-font-lock-fontify-block(#("python" 0 6 (fontified t)) 93 163)
  org-fontify-meta-lines-and-blocks-1(173)
  org-fontify-meta-lines-and-blocks(173)
  font-lock-fontify-keywords-region(1 173 nil)
  font-lock-default-fontify-region(1 173 nil)
  font-lock-fontify-region(1 173)
  #[…](font-lock-fontify-region)
  run-hook-wrapped(#[…] font-lock-fontify-region)
  jit-lock--run-functions(1 173)
  jit-lock-fontify-now(1 501)
  jit-lock-function(1)
  redisplay_internal\ \(C\ function\)()

Cheers,
Clément.

On 2016-12-06 20:41, David Dynerman wrote:
> Dear list,
> 
> For several months I've been encountering a frustrating bug. My emacs hangs while initially loading an org file with ~3000 lines and around two dozen python blocks. If I press C-g during the lockup, emacs wakes up and the file is loaded. The hang does not re-occur after happening on initial load - the bug will reoccur only if I restart emacs and load the file again. The hang seems to be related to fontifying the python blocks: after I abort with C-g, some blocks will be unfontified. 
> 
> I previously emailed the list about this bug (Wed, 17 Aug 2016, subject 'Emacs hangs while loading .org file'), but didn't have an easy way to reproduce the problem.
> 
> I've now managed to extract a minimal org file that reproduces the hang:
> 
> #+BEGIN_SRC python
>   """xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"""
> #+END_SRC
> #+BEGIN_SRC python
>   class x:  
>       def x(self):
>           """
> 	  """
>           pass
> #+END_SRC
> 
> To reproduce:
> 
> 1) Save above as bug.org
> 2) Open a fresh emacs process, and C-x f bug.org <RET>
> 3) Observe emacs is unresponsive. I've let it run as long as 30 mins without any change. 
> 
> I am able to reproduce with emacs -Q, only executing the following in *scratch*:
> 
> (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/org") ;; org from git installed here
> (require 'org)
> 
> This is with the latest org code from git (release_9.0-132-gd65aa3). The bug does NOT occur with org 8.2.10. I've been encountering this bug for several months, but unfortunately I don't remember exactly when I first saw it.
> 
> I'm running GNU Emacs 25.1.1 (x86_64-apple-darwin15.6.0, Carbon Version 157 AppKit 1404.47) of 2016-11-24.
> 
> I'm mystified as to what's going on here. It seems that removing any of the python code in the example above causes the bug to disappear, but I have no clue what the problem might be.
> 
> I've attached a profiler report captured during the hang. Here is the relevant part:
> 
>            - org-src-font-lock-fontify-block                    17419  46%
>             - org-font-lock-ensure                              17240  45%
>              - #<compiled 0x41086c73>                           17240  45%
>               - font-lock-default-fontify-buffer                17240  45%
>                - font-lock-fontify-region                       17240  45%
>                 - font-lock-default-fontify-region              17240  45%
>                  - font-lock-fontify-syntactically-region              17240  45%
>                   - python-font-lock-syntactic-face-function              17240  45%
>                    - python-info-docstring-p                    17240  45%
>                     - python-nav-backward-sexp                  17240  45%
>                      - python-nav-forward-sexp                  17240  45%
>                       - python-nav--forward-sexp                17240  45%
>                        - python-info-end-of-block-p              17240  45%
>                         - python-info-end-of-statement-p              17240  45%
>                          - python-nav-end-of-statement              15444  41%
>                             syntax-ppss                          8641  22%
> 
> It looks like emacs is getting stuck navigating the python blocks during fontification. The last org-mode call appears to be (org-font-lock-ensure).
> 
> If anyone has any suggestions on how to fix this, I'd be very interested to hearthem - I'm working with larger and larger org files containing python code, so I'm encountering this bug frequently.
> 
> Thank you very much,
> David
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Emacs hangs while loading org file with python blocks
  2016-12-07  1:41 Emacs hangs while loading org file with python blocks David Dynerman
  2016-12-07  3:41 ` Clément Pit--Claudel
@ 2016-12-07 13:41 ` Alan Schmitt
  2016-12-07 18:33   ` David Dynerman
  1 sibling, 1 reply; 4+ messages in thread
From: Alan Schmitt @ 2016-12-07 13:41 UTC (permalink / raw)
  To: David Dynerman; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 399 bytes --]

Hello David,

On 2016-12-06 17:41, David Dynerman <emperordali@block-party.net> writes:

> I've now managed to extract a minimal org file that reproduces the hang:

I can confirm it hangs emacs: it even hanged gnus as it was trying to
display your email.

Best,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂, Mauna Loa Obs. 2016-10: 401.57, 2015-10: 398.29

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 454 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Emacs hangs while loading org file with python blocks
  2016-12-07 13:41 ` Alan Schmitt
@ 2016-12-07 18:33   ` David Dynerman
  0 siblings, 0 replies; 4+ messages in thread
From: David Dynerman @ 2016-12-07 18:33 UTC (permalink / raw)
  To: Alan Schmitt, David Dynerman; +Cc: emacs-orgmode

Dear Alan & Clément,

Thanks for trying to reproduce - it's good to know it's not only happening to me.

I've just sent the bug report upstream to bug-gnu-emacs.

David

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> Hello David,
>
> On 2016-12-06 17:41, David Dynerman <emperordali@block-party.net> writes:
>
>> I've now managed to extract a minimal org file that reproduces the hang:
>
> I can confirm it hangs emacs: it even hanged gnus as it was trying to
> display your email.
>
> Best,
>
> Alan
>
> -- 
> OpenPGP Key ID : 040D0A3B4ED2E5C7
> Monthly Athmospheric CO₂, Mauna Loa Obs. 2016-10: 401.57, 2015-10: 398.29

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-07 18:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-07  1:41 Emacs hangs while loading org file with python blocks David Dynerman
2016-12-07  3:41 ` Clément Pit--Claudel
2016-12-07 13:41 ` Alan Schmitt
2016-12-07 18:33   ` David Dynerman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).