Amourspirit / python_ooo_dev_tools

Apache License 2.0
21 stars 5 forks source link

Lo.kill_office() doesn't actually kill the soffice process #537

Closed coandco closed 5 months ago

coandco commented 7 months ago

When you load office with Lo.load_office(Lo.ConnectSocket(headless=True)), three processes are created:

root           2  0.0  0.0   2576   892 ?        S    00:38   0:00 /bin/sh -c "/usr/lib/libreoffice/program/soffice" --norestore --invisible --nofirststartwizard --nologo --headless --accept="socket,host
root           3  0.0  0.0 157724  4552 ?        Sl   00:38   0:00 /usr/lib/libreoffice/program/oosplash --norestore --invisible --nofirststartwizard --nologo --headless --accept=socket,host=localhost,po
root          43  0.8  0.2 921480 183436 ?       Sl   00:38   0:01 /usr/lib/libreoffice/program/soffice.bin --norestore --invisible --nofirststartwizard --nologo --headless --accept=socket,host=localhost

If you then run Lo.kill_office(), it sends a SIGKILL to Lo._lo_inst._lo_inst._soffice_process, which in this case is "2". This results in the following processes running:

root           3  0.0  0.0 157724  4552 ?        Sl   00:38   0:00 /usr/lib/libreoffice/program/oosplash --norestore --invisible --nofirststartwizard --nologo --headless --accept=socket,host=localhost,port=2002,tcpNoDelay=1;urp;
root          43  0.4  0.2 921480 186280 ?       Sl   00:38   0:01 /usr/lib/libreoffice/program/soffice.bin --norestore --invisible --nofirststartwizard --nologo --headless --accept=socket,host=localhost,port=2002,tcpNoDelay=1;urp;

As you can see, only the shell wrapper has actually been killed, and the actual soffice processes are untouched. I believe the correct way to handle this is to send the SIGKILL to the process represented by Lo._lo_inst._lo_inst._soffice_process and all children, either by giving it its own process group when you launch it (and then using os.killpg to kill the group) or via manual crawling of process children.

JulienPalard commented 6 months ago

Probably related but while running with PYTHONDEVMODE=1 I'm seeing:

/usr/lib/python3.11/subprocess.py:1127: ResourceWarning: subprocess 69652 is still running
Amourspirit commented 5 months ago

Thank you for reporting this. I has been corrected in version 0.41.2.