diff --git a/CHANGELOG.md b/CHANGELOG.md index 53814f64..aa6b284c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/FlatCAM.py b/FlatCAM.py index 90c2626c..c944970a 100644 --- a/FlatCAM.py +++ b/FlatCAM.py @@ -87,4 +87,4 @@ if __name__ == '__main__': fc = App() # sys.exit(app.exec_()) - app.exec_() \ No newline at end of file + app.exec_() diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 86f55b4c..579bb07a 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -1428,10 +1428,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; ####################################### @@ -3526,6 +3526,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 @@ -3607,25 +3608,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 @@ -10850,13 +10856,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: @@ -10882,7 +10889,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 diff --git a/FlatCAMTranslation.py b/FlatCAMTranslation.py index 361e6e63..a4ab8f51 100644 --- a/FlatCAMTranslation.py +++ b/FlatCAMTranslation.py @@ -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()