Tkinter/threading issue

Jerrad Genson jerradgenson at gmail.com
Sun Aug 15 16:59:17 EDT 2010


    def check_message(self, spawn=True):
        '''Method for pulling message from server process.'''

        if spawn: self.pid2 = os.fork()
        if self.pid2 == 0:
            if verbose: print('message checker initialized')
            # repeat message check forever
            while True:
                incoming_data = os.read(self.client_receive, 1024)
                if verbose: print('Message receive successful')
                if verbose: print('Message: ' + incoming_data)
                self.update_messages(incoming_data)

    def update_messages(self, new_text=False):
        '''Adds new string to conversation box.
           @param new_text The string to be added.
           '''

        if not new_text: new_text = INCOMING_DATA
        try:
            current_text = self.chat_text.get()
            current_text += '\n' + new_text
            self.chat_text.set(current_text)

        except:
            error_details = 'Fatal Error. Message update failed.
Program will now close.'
            tkMessageBox.showerror('Update Error', error_details)
            error_details += '\nINCOMING_DATA: ' + new_text
            error_details += '\ncurrent_text: ' + current_text
            stack_trace = traceback.format_stack()
            self.error_logger.log_error(stack=stack_trace,
details=error_details)
            self.exit_program(force=True)



More information about the Python-list mailing list