Python Forum
When to call thread.join in a GUI application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When to call thread.join in a GUI application
#1
import wx
import json
import queue
import threading


class MyDialog(wx.Frame):

    def __init__(self, parent, title):
        self.no_resize = wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)
        wx.Frame.__init__(self, parent, title=title, size=(500, 450),style = self.no_resize)

        self.panel = wx.Panel(self, size=(250, 270))
        self.emp_selection = wx.ComboBox(self.panel, -1, pos=(40, 50), size=(200,100))
        self.start_read_thread()

        #code to load other GUI components             

        self.Centre()
        self.Show(True)


    def read_employees(self, read_file):
        list_of_emails = queue.Queue()
        with open(read_file) as f_obj:
            employees = json.load(f_obj)
        list_of_emails = [empEmail for empEmail in employees.keys()]
        wx.CallAfter(self.emp_selection.Append, list_of_emails)

    def start_read_thread(self):
        filename = 'employee.json'
        empThread = threading.Thread(target=self.read_employees, args=(filename,))
        empThread.start()
I have a GUI application that loads a combobox, and starts a thread to read some data and load it into the combobox. I don't want the read to block, so that the other GUI components can load.

After calling thread.start() when is it appropriate to call thread.join()? From my understanding, join() waits for the thread to complete, I don't want that, I want to start the thread and allow all the other components to load. Is it bad practice not to call join()?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send data from a python application to an external application aditya_rajiv 1 2,132 Jul-26-2021, 06:00 AM
Last Post: ndc85430
  The difference between os.path.join( and os.sep.join( Pedroski55 2 9,311 Nov-17-2020, 08:38 AM
Last Post: Pedroski55
  Error SQLite objects created in a thread can only be used in that same thread. binhduonggttn 3 15,394 Jan-31-2020, 11:08 AM
Last Post: DeaD_EyE
  SQL select join operation in python(Select.. join) pradeepkumarbe 1 2,205 Feb-14-2019, 08:34 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020