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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 b= e > five keystrokes. For the console interpreter, this is still true even in 3.5.0a0 >>> ^D File "", line 1 =E2=99=A6 ^ SyntaxError: invalid syntax Idle now quits on ^D on all systems. ^Z (unlike other control chars) is=20 rejected with an immediate error beep. Either way, restart is a single click if one have the console or Idle=20 interpreter icon pinned on the task bar. Even this is unnecessary with Idle as it has a Restart Shell command on=20 the Shell menu (hotkey ^F6). (This is automatically invoked when=20 running an edited file (F5)). Some problems with restarting are unwinding the call stack, undoing=20 what has been done, and doing something else so as to not run into the=20 same problem. We can view every raise -- except pair as a partial=20 restart of some sort. A minimal startup script something like the=20 following allows a nearly global restart that addresses all three=20 problems listed above. from appmain import main, cleanup, RestartError restart =3D False while True: try: main(restart) except RestartError as err: cleanup() restart =3D err continue The main and cleanup functions, switching on the restart arg, and=20 possibly the class RestartError depend on the app. --=20 Terry Jan Reedy