1010import threading
1111import traceback
1212import types
13+ import subprocess
1314
1415import linecache
1516from code import InteractiveInterpreter
3738HOST = '127.0.0.1' # python execution server on localhost loopback
3839PORT = 0 # someday pass in host, port for remote debug capability
3940
40- try :
41- from signal import SIGTERM
42- except ImportError :
43- SIGTERM = 15
44-
4541# Override warnings module to write to warning_stream. Initialize to send IDLE
4642# internal warnings to the console. ScriptBinding.check_syntax() will
4743# temporarily redirect the stream to the shell window to display warnings when
@@ -344,13 +340,12 @@ def __init__(self, tkconsole):
344340 self .port = PORT
345341
346342 rpcclt = None
347- rpcpid = None
343+ rpcsubproc = None
348344
349345 def spawn_subprocess (self ):
350346 if self .subprocess_arglist is None :
351347 self .subprocess_arglist = self .build_subprocess_arglist ()
352- args = self .subprocess_arglist
353- self .rpcpid = os .spawnv (os .P_NOWAIT , sys .executable , args )
348+ self .rpcsubproc = subprocess .Popen (self .subprocess_arglist )
354349
355350 def build_subprocess_arglist (self ):
356351 assert (self .port != 0 ), (
@@ -365,12 +360,7 @@ def build_subprocess_arglist(self):
365360 command = "__import__('idlelib.run').run.main(%r)" % (del_exitf ,)
366361 else :
367362 command = "__import__('run').main(%r)" % (del_exitf ,)
368- if sys .platform [:3 ] == 'win' and ' ' in sys .executable :
369- # handle embedded space in path by quoting the argument
370- decorated_exec = '"%s"' % sys .executable
371- else :
372- decorated_exec = sys .executable
373- return [decorated_exec ] + w + ["-c" , command , str (self .port )]
363+ return [sys .executable ] + w + ["-c" , command , str (self .port )]
374364
375365 def start_subprocess (self ):
376366 addr = (HOST , self .port )
@@ -428,7 +418,7 @@ def restart_subprocess(self):
428418 pass
429419 # Kill subprocess, spawn a new one, accept connection.
430420 self .rpcclt .close ()
431- self .unix_terminate ()
421+ self .terminate_subprocess ()
432422 console = self .tkconsole
433423 was_executing = console .executing
434424 console .executing = False
@@ -469,23 +459,22 @@ def kill_subprocess(self):
469459 self .rpcclt .close ()
470460 except AttributeError : # no socket
471461 pass
472- self .unix_terminate ()
462+ self .terminate_subprocess ()
473463 self .tkconsole .executing = False
474464 self .rpcclt = None
475465
476- def unix_terminate (self ):
477- "UNIX: make sure subprocess is terminated and collect status"
478- if hasattr (os , 'kill' ):
466+ def terminate_subprocess (self ):
467+ "Make sure subprocess is terminated"
468+ try :
469+ self .rpcsubproc .kill ()
470+ except OSError :
471+ # process already terminated
472+ return
473+ else :
479474 try :
480- os . kill ( self .rpcpid , SIGTERM )
475+ self .rpcsubproc . wait ( )
481476 except OSError :
482- # process already terminated:
483477 return
484- else :
485- try :
486- os .waitpid (self .rpcpid , 0 )
487- except OSError :
488- return
489478
490479 def transfer_path (self ):
491480 self .runcommand ("""if 1:
0 commit comments