Open JulienPalard opened 5 days ago
This issue is resolved in the next release.
Okay, the next release 0.47.19
is available. But there is a little more to this.
Lets assume for this discussion that you Already have an instance of LibreOffice running.
If connect to LibreOffice using default settings
def main():
with Lo.Loader(Lo.ConnectSocket(headless=True)):
pass
Then it will connect to the current running instance of LibreOffice.
The trick is to tell the Loader that you want to connect a fresh instance with a copy of your current LibreOffice user profile.
This configuration Starts LibreOffice in headles mode. It also copies an instance of the users current LibreOffice Profile to a temp directory for the duration of the session.
Two instances can run at the same time this way. Now When this session stops your previously opened LibreOffice will remain open due to the different Profiles.
from ooodev.conn.cache import Cache
def main():
with Lo.Loader(Lo.ConnectSocket(headless=True), cache_obj=Cache()):
pass
See more details in Cache Option online documentation.
BTW The Cache
object and the Connection objects now writes debug info to the Log.
Because these objects are created before Lo
sets the logging level you would need to set the logging first to logger.set_log_level(logging.DEBUG)
as this example demonstrates.
import logging
from ooodev.loader.inst.options import Options as LoOptions
from ooodev.loader.lo import Lo
from ooodev.conn.cache import Cache
from ooodev.calc import CalcDoc
from ooodev.io.log import logging as logger
def main():
logger.set_log_level(logging.DEBUG)
options = LoOptions(log_level=logging.DEBUG)
with Lo.Loader(
Lo.ConnectPipe(headless=False),
opt=options,
cache_obj=Cache(profile_path="", no_shared_ext=True),
) as loader:
doc = CalcDoc.create_doc()
sheet = doc.sheets[0]
sheet["A1"].value = 10
doc.close()
if __name__ == "__main__":
main()
Just running my usual reproducer:
but this time I first start OOO manually to edit some unrelated file, then start the script and boom it kills my OOO ☹