Rev 81a2f1e: A rewrite of PyInterp.doEnter & helpers

36 views
Skip to first unread message

Edward K. Ream

unread,
Jun 19, 2019, 8:59:10 PM6/19/19
to leo-editor
Note: this rewrite has no chance of curing the segfaults (#1212) that can happen during startup. That project will wait until 6.1, or later.

For the first time ever, the doEnter code is sound, and contains no egregious hacks:

- It handles continued lines properly, including (for the first time) lines continued via trailing open parens.
- It handles pasted code properly.
- It properly groups statements before passing them to code.compile_command.
  - All unindented lines are compiled and run separately.
  - All indented lines are compiled and run as a group.
- Uses Vitalije's functional style to reduce namespace pollution.

Assuming you can enable this plugin without crashing, I would appreciate further testing.

Edward

Edward K. Ream

unread,
Jun 19, 2019, 9:00:36 PM6/19/19
to leo-editor
On Wednesday, June 19, 2019 at 7:59:10 PM UTC-5, Edward K. Ream wrote:

For the first time ever, the doEnter code is sound...

Well, I forgot to mention that this post refers to the python_terminal plugin.

Edward

Chris George

unread,
Jun 19, 2019, 11:08:27 PM6/19/19
to leo-editor

setting leoID from os.getenv('USER'): 'chris'
Leo 6.0-b1, master branch, build 445dfa149e
2019-06-18 09:45:56 -0500
KCrash: crashing... crashRecursionCounter = 2

The exact same crash on starting Leo.

Chris

Edward K. Ream

unread,
Jun 19, 2019, 11:49:57 PM6/19/19
to leo-editor
On Wed, Jun 19, 2019 at 10:08 PM Chris George <techn...@gmail.com> wrote:

setting leoID from os.getenv('USER'): 'chris'
Leo 6.0-b1, master branch, build 445dfa149e
2019-06-18 09:45:56 -0500
KCrash: crashing... crashRecursionCounter = 2

The exact same crash on starting Leo.

I would have been shocked if that were not true.

BTW, can you send a copy of Leo's log pane when you aren't crashing.  I'm guessing it's some Linux flavor, but I'd like to know the details.

It's time to start thinking about filing a python bug report.

Presumably, the segfault happen in the on-create function.  What I would do, if I were you, would be to put a call to g.pdb() here:

def onCreate (tag, keys):
    '''python_terminal.py onCreate handler.'''
    c = keys.get('c')
    if c:
        g.pdb()
        win = MyInterpreter(None,c)
        c.frame.log.createTab('Python Console',widget=win)

You will very likely take the segfault stepping over the next line.  If so, you can step into that line (the next time), and keep single stepping until you find the line that causes the segfault.

You should be able to find the culprit pretty easily.  This is, after all, a repeatable bug.  Are you game?

Once the cause of the segfault is found, we can work on creating a minimal program that demonstrates it, which is what the python devs will want.

Edward

Chris George

unread,
Jun 20, 2019, 7:31:29 AM6/20/19
to leo-editor

BTW, can you send a copy of Leo's log pane when you aren't crashing.  I'm guessing it's some Linux flavor, but I'd like to know the details.


Leo 6.0-b2-devel, devel branch, build 0e86a7bf76
2019-06-19 21:25:33 -0500
Python 3.6.8, PyQt version 5.12.3
linux

 
It's time to start thinking about filing a python bug report.

Presumably, the segfault happen in the on-create function.  What I would do, if I were you, would be to put a call to g.pdb() here:

def onCreate (tag, keys):
    '''python_terminal.py onCreate handler.'''
    c = keys.get('c')
    if c:
        g.pdb()
        win = MyInterpreter(None,c)
        c.frame.log.createTab('Python Console',widget=win)

You will very likely take the segfault stepping over the next line.  If so, you can step into that line (the next time), and keep single stepping until you find the line that causes the segfault.

Done.
 

You should be able to find the culprit pretty easily.  This is, after all, a repeatable bug.  Are you game?

Sure.
 

Once the cause of the segfault is found, we can work on creating a minimal program that demonstrates it, which is what the python devs will want.

Edward

 No luck, the process never makes it that far.

chris@technatica:~/leo-editor$ python3 ./launchLeo.py --trace=startup

setting leoID
from os.getenv('USER'): 'chris'
reading settings
in /home/chris/leo-editor/leo/config/leoSettings.leo
reading settings
in /home/chris/.leo/myLeoSettings.leo
reading settings
in /home/chris/.leo/themes/BreezeDarkThemeLocal.leo
getGitVersion commit
0e86a7bf76313885be1a75c89367f7ab68869d0e
Author: Edward K. Ream <edreamleo@gmail.com>
Date:   2019-06-19 21:25:33 -0500

   
Documented two completed issues

getGitVersion commit
0e86a7bf76313885be1a75c89367f7ab68869d0e
Author: Edward K. Ream <edreamleo@gmail.com>
Date:   2019-06-19 21:25:33 -0500

   
Documented two completed issues

Leo 6.0-b2-devel, devel branch, build 0e86a7bf76
2019-06-19 21:25:33 -0500

KCrash: crashing... crashRecursionCounter = 2

This is the exact same crash as before.

FYI, before we started this yesterday I deleted my ~/.leo directory and deleted and rebuilt via git my entire Leo installation.

The same behaviour occurs.

This used to trip me up whenever I reinstalled my OS because the plugin was enabled by default in LeoSettings.leo.

HTH and awaiting next steps.

 Chris

Chris George

unread,
Jun 20, 2019, 7:47:30 AM6/20/19
to leo-editor
Bingo!

from rlcompleter import Completer


This is an import that is unique to the plugin.

When I comment it out, Leo starts just fine and I even get a python console.

No errors reported in the log or the concole with --trace=startup enabled.

Chris

Edward K. Ream

unread,
Jun 20, 2019, 8:10:37 AM6/20/19
to leo-editor
On Thu, Jun 20, 2019 at 6:31 AM Chris George <techn...@gmail.com> wrote:

BTW, can you send a copy of Leo's log pane when you aren't crashing.  I'm guessing it's some Linux flavor, but I'd like to know the details.


Leo 6.0-b2-devel, devel branch, build 0e86a7bf76
2019-06-19 21:25:33 -0500
Python 3.6.8, PyQt version 5.12.3
linux
Thanks.  This is now part of #1212.


You should be able to find the culprit pretty easily.  This is, after all, a repeatable bug.  Are you game?

Sure.

Excellent.  My initial guess was wrong.  The segfault happens earlier.  How odd!

HTH and awaiting next steps.

Let's see if python_console.py imports properly.

Put the g.pdb() at the start of python.console.py.  Single step (N: step over) through the file. (You will see that the debugger steps over all functions, and classes.)  If that works, put g.pdb at the start of the top-level init method. 

If both work, we'll do a detailed walk through of Leo's startup.

Edward

Edward K. Ream

unread,
Jun 20, 2019, 8:11:44 AM6/20/19
to leo-editor
On Thu, Jun 20, 2019 at 6:47 AM Chris George <techn...@gmail.com> wrote:
Bingo!

from rlcompleter import Completer


This is an import that is unique to the plugin.

When I comment it out, Leo starts just fine and I even get a python console.

Well done.  I'll take a look.

Edward

Chris George

unread,
Jun 20, 2019, 8:27:29 AM6/20/19
to leo-editor
It is definitely rlcompleter causing the problem.

Chris

Edward K. Ream

unread,
Jun 20, 2019, 9:02:35 AM6/20/19
to leo-editor


On Thu, Jun 20, 2019 at 7:11 AM Edward K. Ream <edre...@gmail.com> wrote:

>> from rlcompleter import Completer


>> Well done.  I'll take a look.

Googling rlcompleter segfault produces several hits.  Some of the bugs are supposedly fixed.

Let's see if we can nail down where the segfault actually happens.  The second comment in #1212  now contains a test program.  Please run it with python and report your experiences.  Strange things happen for me on Windows.

Edward

Edward K. Ream

unread,
Jun 20, 2019, 9:14:32 AM6/20/19
to leo-editor
On Thursday, June 20, 2019 at 8:02:35 AM UTC-5, Edward K. Ream wrote:

The second comment in #1212  now contains a test program.  Please run it with python and report your experiences.  Strange things happen for me on Windows.

Hmm.  It seems that embedding the InteractiveInterpreter class in the Test class is part of the problem.  When I make it a stand-alone class the call to super() in the Test class does indeed return.  Heh.  This is quite apart from rlcompleter, which the test program doesn't exercise.

Edward

Edward K. Ream

unread,
Jun 20, 2019, 9:23:55 AM6/20/19
to leo-editor
On Thursday, June 20, 2019 at 8:14:32 AM UTC-5, Edward K. Ream wrote:

I revised the second comment in #1212 so that the InteractiveInterpreter class is defined at the module level.  Now things are a bit more sane.

Does QTextEdit use InteractiveInterpreter??

Edward

Edward K. Ream

unread,
Jun 20, 2019, 9:34:59 AM6/20/19
to leo-editor


On Thursday, June 20, 2019 at 8:23:55 AM UTC-5, Edward K. Ream wrote:

The second comment in #1212 [defines] the InteractiveInterpreter class...at the module level.

Rev 62dac98 does the same for the actual plugin.

This is the first commit that has any chance of fixing #1212, but I am certainly not counting on it.

Edward

Chris George

unread,
Jun 20, 2019, 10:48:39 AM6/20/19
to leo-e...@googlegroups.com
Good thing.

Exact same crash as before.

Chris

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/801b8fe1-906d-43e1-a93a-036fb38ad1c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages