Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78562

Re: Restarting Python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'interpreter': 0.05; 'startup': 0.05; 'subject:Python': 0.06; 'restarting': 0.07; 'cleanup': 0.09; 'exits': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rejected': 0.09; 'restart': 0.09; 'stack,': 0.09; 'try:': 0.09; 'windows,': 0.09; 'runs': 0.10; 'python': 0.11; 'jan': 0.12; 'systems.': 0.12; '(unlike': 0.16; 'arg,': 0.16; 'cleanup,': 0.16; 'command.': 0.16; 'err:': 0.16; 'fetches': 0.16; 'icon': 0.16; 'interpreter,': 0.16; 'pinned': 0.16; 'quits': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'syntaxerror:': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'command': 0.22; '>>>': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'bar.': 0.24; 'script': 0.25; 'nearly': 0.26; 'possibly': 0.26; 'task': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '(this': 0.29; 'am,': 0.29; 'raise': 0.29; '"",': 0.31; 'app.': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'allows': 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; 'running': 0.33; 'addresses': 0.33; 'minimal': 0.33; 'except': 0.35; 'problem.': 0.35; 'something': 0.35; 'done,': 0.36; 'false': 0.36; 'idle': 0.36; 'doing': 0.36; 'problems': 0.38; 'to:addr :python-list': 0.38; 'previous': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'even': 0.60; 'invalid': 0.68; 'click': 0.77; 'partial': 0.84; 'received:fios.verizon.net': 0.84; 'shell,': 0.91; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Restarting Python
Date Wed, 01 Oct 2014 13:52:57 -0400
References <447m2atpvha8jt21cpulq8qu5p92pmogk3@4ax.com> <542c13f1$0$13007$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding quoted-printable
X-Gmane-NNTP-Posting-Host pool-108-16-203-145.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <542c13f1$0$13007$c3e8da3$5496439d@news.astraweb.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14528.1412186031.18130.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412186031 news.xs4all.nl 2885 [2001:888:2000:d::a6]:59373
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 5180
X-Received-Body-CRC 630585986
Xref csiph.com comp.lang.python:78562

Show key headers only | View raw


On 10/1/2014 10:47 AM, Steven D'Aprano wrote:

> Inside the interactive interpreter, I can restart the interpreter with four
> keystrokes:
>
> - Ctrl-D
> - UP-ARROW
> - ENTER
>
> Ctrl-D exits Python and returns me to the shell, UP-ARROW fetches the
> previous command ("python"), and ENTER runs that command. On Windows, I
> *think* you have to type Ctrl-Z ENTER instead of Ctrl-D, so that will be
> five keystrokes.

For the console interpreter, this is still true even in 3.5.0a0
 >>> ^D
   File "<stdin>", line 1
     ♦
     ^
SyntaxError: invalid syntax

Idle now quits on ^D on all systems. ^Z (unlike other control chars) is 
rejected with an immediate error beep.

Either way, restart is a single click if one have the console or Idle 
interpreter icon pinned on the task bar.

Even this is unnecessary with Idle as it has a Restart Shell command on 
the Shell menu (hotkey ^F6).  (This is automatically invoked when 
running an edited file (F5)).


Some problems with restarting are unwinding the call stack, undoing 
what has been done, and doing something else so as to not run into the 
same problem.  We can view every raise -- except pair as a partial 
restart of some sort.  A minimal startup script something like the 
following allows a nearly global restart that addresses all three 
problems listed above.

from appmain import main, cleanup, RestartError
restart = False
while True:
   try:
     main(restart)
   except RestartError as err:
     cleanup()
     restart = err
     continue

The main and cleanup functions, switching on the restart arg, and 
possibly the class RestartError depend on the app.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Restarting Python Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-30 17:15 -0400
  Re: Restarting Python Grant Edwards <invalid@invalid.invalid> - 2014-09-30 21:27 +0000
    Re: Restarting Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-01 00:24 +0100
  Re: Restarting Python Ned Batchelder <ned@nedbatchelder.com> - 2014-09-30 18:05 -0400
    Re: Restarting Python Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-30 18:07 -0400
      Re: Restarting Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-09-30 22:35 -0400
  Re: Restarting Python Terry Reedy <tjreedy@udel.edu> - 2014-09-30 18:58 -0400
    Re: Restarting Python Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-30 19:16 -0400
      Re: Restarting Python Chris Angelico <rosuav@gmail.com> - 2014-10-01 10:30 +1000
    Re: Restarting Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-01 23:08 +1000
      Re: Restarting Python Rustom Mody <rustompmody@gmail.com> - 2014-10-01 06:39 -0700
  Re: Restarting Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-02 00:47 +1000
    Re: Restarting Python Terry Reedy <tjreedy@udel.edu> - 2014-10-01 13:52 -0400

csiph-web