<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def end(self):
 """Finalise lz4 frame, outputting any remaining as return from this function or by writing to fp)"""

        with self.__lock:
            if self.__write:
                self.__write(compress_end(self.__ctx))
            else:
                return compress_end(self.__ctx)