There is a socket server that is working properly, they asked me to make a minimal interface to it, I did it using PyQt5 there are 2 buttons in it: Starting the server and Shutting down the server, implemented via subprocess as follows:
Launch:
def start_serv(self):
self.process = subprocess.Popen('python server.py', shell=True)
logging.info('#' * 80)
logging.debug(f'Process PID: {self.process.pid}')
logging.debug(f'Child process return code: {self.process.returncode}')
self.mb('The server is running!') # sending a message to a dialog box
Shutdown:
def stop_serv(self):
try:
proc = self.process
proc.send_signal(signal.SIGTERM)
while True:
ex_code = proc.poll()
if ex_code == None or ex_code == '1':
proc.wait()
continue
else:
break
logging.debug(f'Child process exit code: {proc.poll()}')
logging.debug('The server is stopped!')
logging.info('#' * 80)
self.mb('The server is stopped!') # sending a message to a dialog box
except Exception as e:
logging.warning(f'Error button: {e}')
self.mb('The server is not running yet!') # sending a message to a dialog box
Everything works fine in the IDE (PyCharm). But after the build using auto-py-to-exe, when you click on the start button, a process with a new PID is created, but the server does not start. The file paths were not changed during the build.
Please help me figure out where and what edits I need to make to make it work.
P.S.: Everything is done in Python 3.8.2 (customer's requirement)
I thought it was about the path to the script file, I tried different options:
self.path_server = Path(Path.cwd(), 'server.py')
self.process = subprocess.Popen(f'python {self.path_server}', shell=True)
or:
cwd = os.path.dirname(os.path.abspath(__file__))
self.process = subprocess.Popen('python server.py', shell=True, cwd=cwd)
I haven't found any other options for problems yet.