Skip to content

Commit 6cb4dcb

Browse files
committed
readd restart in case libreoffice died unexpectedly
1 parent 2edeb51 commit 6cb4dcb

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

API/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def start_soffice(workers):
2626
os.makedirs("uploads", exist_ok=True)
2727
os.makedirs("exports", exist_ok=True)
2828
clean_temp_files()
29-
3029
my_lo=ot.start_multi_office(nb_env=workers)
3130

3231

lotemplate/connexion.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
from typing import Union
1414
from sorcery import dict_of
15-
15+
import shlex,subprocess
1616
import uno
1717
import unohelper
1818
from com.sun.star.beans import PropertyValue
@@ -27,7 +27,25 @@
2727
from .utils import *
2828
import pdb
2929

30+
def start_office(host:str="localhost",port:str="2000"):
31+
"""
32+
start one process LibreOffice
33+
34+
:param host: define host in the UNO connect-string --accept
35+
:param port: define port in the UNO connect-string --accept
36+
environnement had to be different for each environnement
37+
"""
38+
39+
subprocess.Popen(
40+
shlex.split('soffice \
41+
-env:UserInstallation="file:///tmp/LibO_Process'+port+'" \
42+
-env:UserInstallation="file:///tmp/LibO_Process'+port+'" \
43+
"--accept=socket,host="'+host+',port='+port+';urp;" \
44+
--headless --nologo --terminate_after_init \
45+
--norestore " '), shell=False, stdin = subprocess.PIPE,
46+
stdout = subprocess.PIPE,)
3047

48+
return host, port,'file:///tmp/LibO_Process'+str(port)
3149

3250

3351
class Connexion:
@@ -53,14 +71,15 @@ def __init__(self, host: str, port: str):
5371
self.host = host
5472
self.port = port
5573
self.local_ctx = uno.getComponentContext()
56-
for attempt in range(10):
74+
for attempt in range(3):
5775
try:
5876
self.ctx = self.local_ctx.ServiceManager.createInstanceWithContext(
5977
"com.sun.star.bridge.UnoUrlResolver", self.local_ctx
6078
).resolve(f"uno:socket,host={host},port={port};urp;StarOffice.ComponentContext")
6179
except (NoConnectException, RuntimeException) as e:
62-
if attempt < 9:
63-
sleep(1)
80+
if attempt < 2:
81+
start_office(host,port)
82+
sleep(2)
6483
else:
6584
raise errors.UnoException(
6685
'connection_error',

0 commit comments

Comments
 (0)