2121
2222import sys
2323import os
24+ import shlex
25+ import signal
26+ import subprocess
2427from .qt import QtCore
2528from .websocket_client import WebSocketClient
2629
@@ -42,8 +45,7 @@ def __init__(self):
4245 self ._local_server = None
4346 self ._remote_servers = {}
4447 self ._local_server_path = ""
45- self ._local_server_proccess = QtCore .QProcess ()
46- self ._local_server_proccess .setWorkingDirectory (os .curdir )
48+ self ._local_server_proccess = None
4749 self ._loadSettings ()
4850 self ._remote_server_iter_pos = 0
4951
@@ -129,34 +131,44 @@ def startLocalServer(self, path, host, port):
129131 Starts the local server process.
130132 """
131133
132- params = [ ' --host=' + host , ' --port=' + str (port )]
134+ params = ' --host=' + host + ' --port=' + str (port )
133135 # start the server, use Python on all platform but Windows (in release mode)
134136 if sys .platform .startswith ('win' ) and os .path .splitext (path )[1 ] == '.exe' :
135137 executable = '"' + path + '"'
136138 elif hasattr (sys , "frozen" ):
137139 executable = "python3"
138- params = [ path ] + params
140+ params = path + params
139141 else :
140142 executable = sys .executable
141- params = [ path ] + params
143+ params = path + params
142144
143- log . info ( "starting local server process {} with {}" . format ( executable , params ))
144- self . _local_server_proccess . start ( executable , params )
145+ command = executable + ' ' + params
146+ log . info ( "starting local server process with {}" . format ( command ) )
145147
146- if self ._local_server_proccess .waitForStarted () == False :
148+ try :
149+ if sys .platform .startswith ("win" ):
150+ # use the string on Windows
151+ self ._local_server_proccess = subprocess .Popen (command )
152+ else :
153+ # use arguments on other platforms
154+ args = shlex .split (command )
155+ self ._local_server_proccess = subprocess .Popen (args )
156+ except EnvironmentError as e :
157+ log .warning ('could not start local server "{}": {}' .format (command , e ))
147158 return False
159+
148160 return True
149161
150162 def stopLocalServer (self , wait = False ):
151163
152- if self ._local_server and self . _local_server . connected () :
153- self ._local_server . close_connection ()
154- if self . _local_server_proccess . state () == QtCore . QProcess . Running :
155- log . info ( "stopping local server process " )
156- self ._local_server_proccess . terminate ()
157- if wait :
158- self ._local_server_proccess .waitForFinished ( )
159- self ._local_server_proccess .close ()
164+ if self ._local_server_proccess :
165+ if self ._local_server and self . _local_server . connected ():
166+ log . info ( "sending stop request to the server" )
167+ self . _local_server . send_notification ( "builtin.stop " )
168+ self ._local_server . close_connection ()
169+ else :
170+ self ._local_server_proccess .send_signal ( signal . SIGINT )
171+ self ._local_server_proccess .wait ()
160172
161173 def setLocalServer (self , path , host , port ):
162174 """
0 commit comments