<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def listen(self, listener):
        '''Listen for events that affect our ownership of a job'''
        for message in listener.listen():
            try:
                data = json.loads(message['data'])
                if data['event'] in ('canceled', 'lock_lost', 'put'):
                    self.kill(data['jid'])
            except:
                logger.exception('Pubsub error')