Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'elif': 0.05; 'true,': 0.05; 'editor.': 0.09; 'false.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:command': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'random': 0.14; 'changes': 0.15; '"run': 0.16; '(about': 0.16; '(starting': 0.16; '10:17': 0.16; 'added.': 0.16; 'behavior,': 0.16; 'command.': 0.16; 'editor,': 0.16; 'files)': 0.16; 'finished."': 0.16; 'given,': 0.16; 'grep': 0.16; 'invokes': 0.16; 'invoking': 0.16; 'normally,': 0.16; 'normally.': 0.16; 'omitted,': 0.16; 'pressing': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'reproduce': 0.16; 'spawn': 0.16; 'subject:already': 0.16; 'written.': 0.16; 'zeros': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'finished': 0.19; 'normally': 0.19; 'starts': 0.20; '>>>': 0.22; 'import': 0.22; 'shell': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'skip:i 40': 0.24; 'second': 0.26; 'post': 0.26; 'skip:" 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'am,': 0.29; 'instruction': 0.29; 'raise': 0.29; 'gives': 0.31; 'program,': 0.31; 'code': 0.31; 'getting': 0.31; 'lines': 0.31; 'you?': 0.31; '"please': 0.31; 'option.': 0.31; 'sep': 0.31; 'this.': 0.32; 'run': 0.32; 'running': 0.33; 'minimal': 0.33; 'not.': 0.33; 'third': 0.33; '"the': 0.34; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'could': 0.34; 'message.': 0.35; 'problem.': 0.35; 'skip:s 30': 0.35; 'editor': 0.35; 'one,': 0.35; 'but': 0.35; 'there': 0.35; 'executing': 0.36; 'false': 0.36; 'idle': 0.36; 'shows': 0.36; 'changing': 0.37; 'so,': 0.37; 'expected': 0.38; 'sometimes': 0.38; 'window': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'previous': 0.38; 'little': 0.38; 'generating': 0.39; 'to:addr:python.org': 0.39; 'unable': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'deleting': 0.60; 'new': 0.61; 'first': 0.61; 'back': 0.62; 'times': 0.62; 'making': 0.63; 'here': 0.66; 'below.': 0.71; 'connection.': 0.74; 'click': 0.77; 'code):': 0.84; 'received:fios.verizon.net': 0.84; 'rounds,': 0.84; 'cancelled': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: the python shell window is already executing a command Date: Wed, 17 Sep 2014 18:56:47 -0400 References: <4jrh1adtbsvnr9o20r9k3hfe4nkrkps2dk@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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: 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: 109 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410994642 news.xs4all.nl 2852 [2001:888:2000:d::a6]:60991 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77985 On 9/17/2014 11:55 AM, Seymore4Head wrote: > On Wed, 17 Sep 2014 04:02:16 -0400, Terry Reedy > wrote: >> On 9/16/2014 10:17 PM, Seymore4Head wrote: >>> What I do is click on the IDLE window and without making any changes I >>> just hit f5 to rerun the program. >>> Sometimes I get the error "the python shell window is already >>> executing a command" and sometimes not. You left out an important part of the error message ""please wait until it is finished." >>> I am using XP and Python 3.4.1. I am using 3.4.1 on Win 7. >>> Is there a way to rerun a program without getting this error? Follow the instruction you were given, but omitted, or see below. >> Normally, hitting f5 kills the previous process if it is still running >> and starts the one in the editor. Please post a minimal program that >> exhibits the problem. > > It happens in almost every program I have written. I just tried this > one again. I could run the program by pushing f5. The first couple > of times it would run again by switching back to IDLE and pressing f5, > but after the second or third time, it gives an error that the python > shell window is already executing a command. > > If I make a change to the program, like adding or deleting a 0 from > "rounds" the program will run without generating an error, but if I > try to re run the program without changing anything, I get the error > almost every time. > > > Here is one. > > import random > count =0 > rounds=1000 > heads=0 > tails=0 > ht=[0,1] > while count coin=random.choice(ht) > if coin == 0: > heads=heads+1 > elif coin == 1: > tails=tails+1 > count = count + 1 > print (heads,tails) > print ('Heads {:.2%} Tails "{:.2%} "'.format(heads/rounds, > tails/rounds)) I am unable to reproduce the problem. When I run this program from an Idle editor, it finished before I can click on the Editor window and hit F5 again. The same remains true with 1 or 2 zeros added. With 1000000 rounds, I get the expected behavior, which is no ouput from the cancelled process and a clean restart. A little digging with Idle's grep (Find in Files) shows that the message is produced by this code in idlelib/PyShell.py, about 825. def display_executing_dialog(self): tkMessageBox.showerror( "Already executing", "The Python Shell window is already executing a command; " "please wait until it is finished.", master=self.tkconsole.text) This function is only called here (about line 735) def runcommand(self, code): "Run the code without invoking the debugger" # The code better not raise an exception! if self.tkconsole.executing: self.display_executing_dialog() How is this run? Run-Module F5 invokes ScriptBinding.run_module_event(116) and thence _run_module_event (129). This methods includes this. if PyShell.use_subprocess: interp.restart_subprocess(with_cwd=False) restart_subprocess includes these lines (starting at 470): # Kill subprocess, spawn a new one, accept connection. self.rpcclt.close() self.terminate_subprocess() console = self.tkconsole ... console.executing = False # == self.tkconsole ... self.transfer_path(with_cwd=with_cwd) transfer_path calls runcommand but only after tkconsole.executing has been set to False. But this only happens if PyShell.use_subprocess is True, which it normally is, but not if one starts Idle with the -n option. After conditionally calling interp.restart_subprocess, _run_module_event directly calls interp.runcommand, which can fail when running with -n. Are you? This is the only way I know to get the error message. Is so, the second way to not get the error message is to not use -n and run normally. -- Terry Jan Reedy