class ThreadedClient: """ Launch the main part of the GUI and the worker thread. """ def __init__(self, master, read_data): """ Start the GUI and the asynchronous threads. """ self.master = master # Create the queue self.queue = Queue.Queue() # Set up the GUI part self.gui = GUI(master, self.queue) # Set up data read self._data = read_data # Set up the thread to do asynchronous I/O self.running = 1 self.thread = threading.Thread(target=self.worker_thread) self.thread.start() # Start the periodic call in the GUI to check queue self.periodic_call() def periodic_call(self): """ Check every 100 ms if there is something new in the queue. """ self.gui.process_incoming() if not self.running: # Hard stop of application if running is not set import sys sys.exit(1) self.master.after(100, self.periodic_call) def worker_thread(self): """ Handle the asynchronous I/O. """ while self.running: time.sleep(5) msg = "Poll" _data = self._data._read_current_weather() self._data.create_data_chunks(_data) self.gui.set_weather_data(self._data.location, self._data.current, self._data.condition) self.gui.update_labels() self.master.update_idletasks() self.queue.put(msg)