Leo: a programmer's editor and more

Ctrl-B plus argparse equals immediate exit from Leo-Editor

Reported by SegundoBob on 2012-02-28
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
leo-editor
Low
Unassigned

Bug Description

This may well be behavior that can't be fixed. It may even be behavior that should not be fixed.

If script execution such as Ctrl-B causes the Python standard library module argparse to parse the command line passed to the script and argparse reports an error, then Leo-Editor immediately exits with no error or warning.

My simplest test case is a Leo-Editor file containing exactly one node with body:

import argparse
parser = argparse.ArgumentParser()
args = parser.parse_args()
---- End of node----

Test procedure:
Open Leo-Editor file (above).
Ctrl-b
Note immediate exit.

Log pane on Leo-Editor entry:
Leo Log Window
Leo 4.9.1 devel, build 5041, 2012-02-28 11:16:17
Python 2.7.2, qt version 4.7.3
linux2
setting leoID from os.getenv('USER'): 'bob'
load dir: /home/bob/bzr/LeoLatest/leo/core
global config dir: /home/bob/bzr/LeoLatest/leo/config
home dir: /home/bob
reading settings in /home/bob/bzr/LeoLatest/leo/config/leoSettings.leo
reading settings in /home/bob/.leo/myLeoSettings.leo
reading settings in /home/bob/bzr/sqlite3/sqlite3_chrono/trunk/x.leo
reading: /home/bob/bzr/sqlite3/sqlite3_chrono/trunk/x.leo
--------End Log pane-----

Console contents from test run:

11:33:13 ~/bzr/sqlite3/sqlite3_chrono/trunk$ leomy x.leo

** isPython3: False
Leo 4.9.1 devel, build 5041, 2012-02-28 11:16:17
Python 2.7.2, qt version 4.7.3
linux2
reading settings in /home/bob/bzr/LeoLatest/leo/config/leoSettings.leo
reading settings in /home/bob/.leo/myLeoSettings.leo
reading settings in /home/bob/bzr/sqlite3/sqlite3_chrono/trunk/x.leo
usage: launchLeo.py [-h]
launchLeo.py: error: unrecognized arguments: /home/bob/bzr/sqlite3/sqlite3_chrono/trunk/x.leo
11:37:19 ~/bzr/sqlite3/sqlite3_chrono/trunk$
---End Console contents----

I ran this test under Ubuntu 11.10 with the Fluxbox window manager.

On Tue, Feb 28, 2012 at 1:41 PM, SegundoBob <email address hidden> wrote:
> Public bug reported:
>
> This may well be behavior that can't be fixed.   It may even be behavior
> that should not be fixed.

Leo exits even if the script encloses the call to parser.parse_args()
in a try/except statement.

However, I see no reason to call this a Leo bug. It's more like an
obscure warning...

Edward

Changed in leo-editor:
status: New → Won't Fix
importance: Undecided → Low
SegundoBob (bhossley) wrote :

Edward,

Your inability to catch the exception made me wonder if argparse does something that it should not do. So I wrote the following script and ran it from a command line. That is, Leo-editor was not involved. As usual my test system is Ubuntu 11.10 with Fluxbox window manager.

Begin x1.py:

#!/usr/bin/python
#coding=utf-8
import argparse
import sys
import traceback

print('Begin Text')
try:
    parser = argparse.ArgumentParser()
    args = parser.parse_args()
except:
    print('Test Caught Error')
    traceback.print_exception(*sys.exc_info())
print('Exit Test')
---End x1.py-----

Begin console:
17:24:00 ~/tmp$ ./x1.py 1 2 3
Begin Text
usage: x1.py [-h]
x1.py: error: unrecognized arguments: 1 2 3
Test Caught Error
Traceback (most recent call last):
  File "./x1.py", line 10, in <module>
    args = parser.parse_args()
  File "/usr/lib/python2.7/argparse.py", line 1691, in parse_args
    self.error(msg % ' '.join(argv))
  File "/usr/lib/python2.7/argparse.py", line 2347, in error
    self.exit(2, _('%s: error: %s\n') % (self.prog, message))
  File "/usr/lib/python2.7/argparse.py", line 2335, in exit
    _sys.exit(status)
SystemExit: 2
Exit Test
17:24:39 ~/tmp$
----End console-----

Maybe argparse should not "system exit"? But outside of Leo-Editor, I am able to catch this exception.
I hope you find this information useful.

On Thu, Mar 1, 2012 at 7:47 PM, SegundoBob <email address hidden> wrote:

> Maybe argparse should not "system exit"?  But outside of Leo-Editor, I am able to catch this exception.

Thanks for this update. Ctrl-b uses exec to execute the script, so
perhaps this is side effect of exec. In any case, I don't believe
argparse is Leo's problem.

Edward

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers