Execution on different revit model scenarios and UI behavior

Hello, I’m leveraging the pyrevit run command, using the models txt file with the list of revit models to execute my script on each one. The files I have to process are of any kind on how they were saved: local, attached to central model with worksets and files showing “incorrect user” when opening them.
I have to handle all those scenarios, for that I’m using the OpenOptions class and define it as:

AllowOpeningLocalByWrongUser = True
DetachFromCentralOption = DetachAndDiscardWorksets

Also, the detachAndPromp parameter is defined as False when calling the OpenAndActivateDocument menthod.

The files are processed (I run my script of data extraction in csv files per each model). But at the end the Revit application never closes and the pyrevit run command execution hangs, until I manually go over all the files and saved them as detached models (I can’t just simply go and close revit manually, revit is forcing me to save the model).

The expected behavior I need is to close the files and exit Revif application. Is there a way to do so?

Also, I noticed the pyrevit run command opens the files and they are not closed, they remain in the apication, I think I will exhaust the VM if I have 100s of files to process and keep them open. Is there a way to close each one after script execution?

Sorry for the long post and I’d appreciate any input on this

Thanks,
Diego