def completed_task(self):
        """ Handle wrapping up a completed task, local or remote"""
        # If its remote and finished running
        if self.remote_channel and self.remote_channel.exit_status_ready():
            # Collect all remaining stdout/stderr
            while self.remote_channel.recv_ready():
                self.stdout += self.remote_channel.recv(1024)
            while self.remote_channel.recv_stderr_ready():
                self.stderr += self.remote_channel.recv_stderr(1024)
            return self.remote_channel.recv_exit_status()
        # Otherwise check for finished local command
        elif self.process:
            self.stdout, self.stderr = (self._read_temp_file(self.stdout_file),
                                        self._read_temp_file(self.stderr_file))
            for temp_file in [self.stdout_file, self.stderr_file]:
                temp_file.close()
            return self.process.returncode
def completed_task ( self ) : if self . remote_channel and self . remote_channel . exit_status_ready ( ) : while self . remote_channel . recv_ready ( ) : self . stdout += self . remote_channel . recv ( 1024 ) while self . remote_channel . recv_stderr_ready ( ) : self . stderr += self . remote_channel . recv_stderr ( 1024 ) return self . remote_channel . recv_exit_status ( ) elif self . process : self . stdout , self . stderr = ( self . _read_temp_file ( self . stdout_file ) , self . _read_temp_file ( self . stderr_file ) ) for temp_file in [ self . stdout_file , self . stderr_file ] : temp_file . close ( ) return self . process . returncode
Handle wrapping up a completed task, local or remote