<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def finish_and_die(self):
 """ If there is a request pending, let it finish and be handled, then disconnect and die. If not, cancel any pending queue requests and just die. """

        self.logstate('finish_and_die')
        self.stop_working_on_queue()
        if self.jobphase != 'pending_request':
            self.stopFactory()