def thread(self):
        '''Run in a thread'''
        thread = threading.Thread(target=self.listen)
        thread.start()
        try:
            yield self
        finally:
            self.unlisten()
            thread.join()
def thread ( self ) : thread = threading . Thread ( target = self . listen ) thread . start ( ) try : yield self finally : self . unlisten ( ) thread . join ( )
Run in a thread