After you have closed the file, as you know LO will continue to run in the background unless you tell it to terminate, the command for which is starDesktop.terminate. To create a clean shutdown, that does not later prompt for file recovery, a substantial Wait appears necessary prior to the terminate command because of an apparent race condition in LibreOffice. Your Wait may need to be longer, or it might be shorter. Thus the sequence ending with the clean terminate command would be:
ThisComponent.close(True)

Called by itself, the terminate command does generate a save prompt if the current document is modified, but the shutdown typically will be unclean due to the noted race condition.