- added a try-except clause in the FlatCAMTranslation.restart_program() when closing the Listener and the thread that runs it to adjust to MacOS usage

This commit is contained in:
Marius Stanciu 2020-04-29 07:37:33 +03:00 committed by Marius
parent 907e4bc6d9
commit e1bc55a090
4 changed files with 34 additions and 16 deletions

View File

@ -7,6 +7,10 @@ CHANGELOG for FlatCAM beta
=================================================
29.04.2020
- added a try-except clause in the FlatCAMTranslation.restart_program() when closing the Listener and the thread that runs it to adjust to MacOS usage
28.04.2020
- handled a possible situation in App.load_defaults() method

View File

@ -87,4 +87,4 @@ if __name__ == '__main__':
fc = App()
# sys.exit(app.exec_())
app.exec_()
app.exec_()

View File

@ -2655,10 +2655,10 @@ class App(QtCore.QObject):
self.ui.general_defaults_form.general_app_group.version_check_cb.get_value() is True:
App.log.info("Checking for updates in backgroud (this is version %s)." % str(self.version))
self.thr2 = QtCore.QThread()
# self.thr2 = QtCore.QThread()
self.worker_task.emit({'fcn': self.version_check,
'params': []})
self.thr2.start(QtCore.QThread.LowPriority)
# self.thr2.start(QtCore.QThread.LowPriority)
# ###########################################################################################################
# ##################################### Register files with FlatCAM; #######################################
@ -5164,6 +5164,7 @@ class App(QtCore.QObject):
:return: None
"""
if self.save_in_progress:
self.inform.emit('[WARNING_NOTCL] %s' % _("Application is saving the project. Please wait ..."))
return
@ -5245,25 +5246,30 @@ class App(QtCore.QObject):
log.debug("App.quit_application() --> App UI state saved.")
# try to quit the QThread that run ArgsThread class
try:
self.th.quit()
except Exception as e:
log.debug("App.quit_application() --> %s" % str(e))
# try to quit the Socket opened by ArgsThread class
try:
self.new_launch.thread_exit = True
self.new_launch.listener.close()
except Exception as err:
log.debug("App.quit_application() --> %s" % str(err))
# try to quit the QThread that run ArgsThread class
try:
self.th.terminate()
except Exception as e:
log.debug("App.quit_application() --> %s" % str(e))
# terminate workers
self.workers.__del__()
# quit app by signalling for self.kill_app() method
# self.close_app_signal.emit()
QtWidgets.qApp.quit()
# When the main event loop is not started yet in which case the qApp.quit() will do nothing
# we use the following command
# sys.exit(0)
os._exit(0) # fix to work with Python 3.8
@staticmethod
@ -12919,13 +12925,14 @@ class ArgsThread(QtCore.QObject):
def __init__(self):
super(ArgsThread, self).__init__()
self.listener = None
self.thread_exit = False
self.start.connect(self.run)
def my_loop(self, address):
try:
self.listener = Listener(*address)
while True:
while self.thread_exit is False:
conn = self.listener.accept()
self.serve(conn)
except socket.error:
@ -12951,7 +12958,7 @@ class ArgsThread(QtCore.QObject):
self.serve(conn)
def serve(self, conn):
while True:
while self.thread_exit is False:
msg = conn.recv()
if msg == 'close':
break

View File

@ -184,11 +184,18 @@ def restart_program(app, ask=None):
else:
resource_loc = 'assets/resources'
# close the Socket in ArgsThread class
app.new_launch.listener.close()
# try to quit the Socket opened by ArgsThread class
try:
app.new_launch.thread_exit = True
app.new_launch.listener.close()
except Exception as err:
log.debug("FlatCAMTranslation.restart_program() --> %s" % str(err))
# close the QThread that runs ArgsThread class
app.th.quit()
# try to quit the QThread that run ArgsThread class
try:
app.th.quit()
except Exception as err:
log.debug("FlatCAMTranslation.restart_program() --> %s" % str(err))
if app.should_we_save and app.collection.get_list() or ask is True:
msgbox = QtWidgets.QMessageBox()