python_ooo_dev_tools
python_ooo_dev_tools copied to clipboard
Cannot use the context manager on Lo.Loader twice?
Got an interesing case today:
from ooodev.loader.lo import Lo
def b():
with Lo.Loader(Lo.ConnectSocket(headless=True)) as loader1:
pass
with Lo.Loader(Lo.ConnectSocket(headless=True)) as loader2:
print(youpi)
b()
notice the NameError
on the print line: it should be displayed but it's not. The exception is not "eaten" or magically disapearing, that's just the Python process being kind of killed around the __enter__
of loader2, so I think the NameError
does not even occur.
Digging a bit, please hold the line [...]
Ohh found it, loader/lo.py:706
a raise SystemExit(1)
, it happens because of another exception:
ooodev/loader/lo.py(695)load_office()
-> cls._lo_inst.global_event_broadcaster.add_event_document_event_occurred(_on_global_document_event)
(Pdb)
AttributeError: 'NoneType' object has no attribute 'global_event_broadcaster'
A more verbose one could be:
def b():
options = LoOptions(log_level=logging.DEBUG)
with Lo.Loader(Lo.ConnectSocket(headless=True), opt=options) as loader1:
pass
print("-" * 80)
with Lo.Loader(Lo.ConnectSocket(headless=True), opt=options) as loader2:
print(youpi)
this gives:
05/10/2024 00:07:25 - DEBUG - LoInst - Root: LoInst Init
05/10/2024 00:07:25 - DEBUG - LoInst - Root: LoInst created
05/10/2024 00:07:25 - DEBUG - LoInst - Root: load_office()
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_reset() Triggering RESET
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_reset() RESET Triggered. Current Doc is None
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_office_loading() Triggering OFFICE_LOADING
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_office_loading() Triggered OFFICE_LOADING.
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_office_loaded() Triggering OFFICE_LOADED
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_office_loaded() Triggered OFFICE_LOADED
05/10/2024 00:07:25 - DEBUG - LoInst - Root: load_office() Loaded Office
05/10/2024 00:07:25 - DEBUG - LoInst - Root: Closing Office
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_office_closing() Triggering OFFICE_CLOSING
05/10/2024 00:07:25 - DEBUG - LoInst - Root: on_office_closing() Triggered OFFICE_CLOSING
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_office_closed() Triggering OFFICE_CLOSED
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_office_closed() Triggered OFFICE_CLOSED
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_reset() Triggering RESET
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_reset() RESET Triggered. Current Doc is None
--------------------------------------------------------------------------------
05/10/2024 00:07:26 - DEBUG - LoInst - Root: LoInst Init
05/10/2024 00:07:26 - DEBUG - LoInst - Root: LoInst created
05/10/2024 00:07:26 - DEBUG - LoInst - Root: load_office()
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_reset() Triggering RESET
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_reset() RESET Triggered. Current Doc is None
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_office_loading() Triggering OFFICE_LOADING
05/10/2024 00:07:26 - DEBUG - LoInst - Root: on_office_loading() Triggered OFFICE_LOADING.
/usr/lib/python3.12/subprocess.py:1127: ResourceWarning: subprocess 992727 is still running
_warn("subprocess %s is still running" % self.pid,
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib/python3.12/subprocess.py:1127: ResourceWarning: subprocess 992709 is still running
_warn("subprocess %s is still running" % self.pid,
ResourceWarning: Enable tracemalloc to get the object allocation traceback