Skip to content

Commit 057b298

Browse files
committed
Fixed loffice/gunicorn process no. not matching.
1 parent 1dbac4a commit 057b298

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

config.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
# dpi used for images in TESSERACT and other stuff
5858
OCR_IMAGE_DPI = int(os.environ.get("OCR_SERVICE_IMAGE_DPI", 200))
5959

60-
6160
# LIBRE OFFICE SECTION
6261

6362
# 60 seconds before terminating processes
@@ -69,8 +68,15 @@
6968
# a libre office server will only use 1 CPU by default (not changable), thus,
7069
# for handling multiple requests, we will have one service per OCR_WEB_SERVICE_THREAD
7170
DEFAULT_LIBRE_OFFICE_SERVER_PORT = 9900
72-
LIBRE_OFFICE_LISTENER_PORT_RANGE = range(DEFAULT_LIBRE_OFFICE_SERVER_PORT, DEFAULT_LIBRE_OFFICE_SERVER_PORT + OCR_WEB_SERVICE_THREADS + OCR_WEB_SERVICE_WORKERS)
7371

72+
LIBRE_OFFICE_PORT_CAP = DEFAULT_LIBRE_OFFICE_SERVER_PORT + 1
73+
74+
if OCR_WEB_SERVICE_THREADS > 1:
75+
LIBRE_OFFICE_PORT_CAP += OCR_WEB_SERVICE_THREADS
76+
if OCR_WEB_SERVICE_WORKERS > 1:
77+
LIBRE_OFFICE_PORT_CAP += OCR_WEB_SERVICE_WORKERS
78+
79+
LIBRE_OFFICE_LISTENER_PORT_RANGE = range(DEFAULT_LIBRE_OFFICE_SERVER_PORT, LIBRE_OFFICE_PORT_CAP)
7480
LIBRE_OFFICE_NETWORK_INTERFACE = "localhost"
7581

7682

ocr_service/app/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ def start_office_converter_servers():
4848

4949
port_count = 0
5050
for port_num in LIBRE_OFFICE_LISTENER_PORT_RANGE:
51-
if OCR_WEB_SERVICE_WORKERS <= 1:
52-
if port_count < OCR_WEB_SERVICE_THREADS:
53-
port_count += 1
51+
if OCR_WEB_SERVICE_WORKERS > 1:
52+
if port_count < 1:
5453
if port_num not in list(loffice_processes.keys()):
54+
port_count += 1
5555
if is_port_in_use(port_num) == False:
5656
loffice_processes[port_num] = start_office_server(port_num)
5757
else:
5858
break
5959
else:
6060
print("WOREKER TRYING PORT " + str(port_num))
61-
if is_port_in_use(port_num) == False and port_count < OCR_WEB_SERVICE_WORKERS:
61+
if is_port_in_use(port_num) == False and port_count < OCR_WEB_SERVICE_THREADS:
6262
loffice_processes[port_num] = start_office_server(port_num)
6363
port_count += 1
6464
else:

0 commit comments

Comments
 (0)