def stop(self):
self.stop_now = True<EOL>self.history_manager.save_flag.set()<EOL>self.join()<EOL>
This can be called from the main thread to safely stop this thread.

        Note that it does not attempt to write out remaining history before
        exiting. That should be done by calling the HistoryManager's
        end_session method.