Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes unsafe multithread mechanism in button_run #451

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions kicost/kicost_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import sys
import os
import subprocess # To access OS commands and run in the shell.
import threading
from threading import Thread
import time # To elapse time.
import tempfile # To create the temporary log file.
from datetime import datetime # To create the log name, when asked to save.
Expand Down Expand Up @@ -96,6 +96,18 @@
kicostPath = os.path.dirname(os.path.abspath(__file__)) # Application dir.


# ======================================================================
class ChildThread(Thread):
""" Helper class to safetly call the run action """
def __init__(self, myframe):
"""Init Worker Thread Class."""
Thread.__init__(self)
self.myframe = myframe

def run(self):
wx.CallAfter(self.myframe.run)


# ======================================================================
def open_file(filepath):
'''@brief Open a file with the default application in different OSs.
Expand Down Expand Up @@ -714,10 +726,9 @@ def addFile(self, filesName):
def button_run(self, event):
''' @brief Call to run KiCost.'''
event.Skip()
# self.run()
# wx.CallLater(10, self.run) # Necessary to not '(core dumped)' with wxPython.
t = threading.Thread(target=self.run) # , args=[self])
t.start()
self.child = ChildThread(myframe=self)
self.child.daemon = True
self.child.start()

# ----------------------------------------------------------------------
# @anythread
Expand Down