Skip to content

Commit

Permalink
Fixed loffice/gunicorn process no. not matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladd-bit committed Jun 28, 2023
1 parent 1dbac4a commit 057b298
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
# dpi used for images in TESSERACT and other stuff
OCR_IMAGE_DPI = int(os.environ.get("OCR_SERVICE_IMAGE_DPI", 200))


# LIBRE OFFICE SECTION

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

LIBRE_OFFICE_PORT_CAP = DEFAULT_LIBRE_OFFICE_SERVER_PORT + 1

if OCR_WEB_SERVICE_THREADS > 1:
LIBRE_OFFICE_PORT_CAP += OCR_WEB_SERVICE_THREADS
if OCR_WEB_SERVICE_WORKERS > 1:
LIBRE_OFFICE_PORT_CAP += OCR_WEB_SERVICE_WORKERS

LIBRE_OFFICE_LISTENER_PORT_RANGE = range(DEFAULT_LIBRE_OFFICE_SERVER_PORT, LIBRE_OFFICE_PORT_CAP)
LIBRE_OFFICE_NETWORK_INTERFACE = "localhost"


Expand Down
8 changes: 4 additions & 4 deletions ocr_service/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ def start_office_converter_servers():

port_count = 0
for port_num in LIBRE_OFFICE_LISTENER_PORT_RANGE:
if OCR_WEB_SERVICE_WORKERS <= 1:
if port_count < OCR_WEB_SERVICE_THREADS:
port_count += 1
if OCR_WEB_SERVICE_WORKERS > 1:
if port_count < 1:
if port_num not in list(loffice_processes.keys()):
port_count += 1
if is_port_in_use(port_num) == False:
loffice_processes[port_num] = start_office_server(port_num)
else:
break
else:
print("WOREKER TRYING PORT " + str(port_num))
if is_port_in_use(port_num) == False and port_count < OCR_WEB_SERVICE_WORKERS:
if is_port_in_use(port_num) == False and port_count < OCR_WEB_SERVICE_THREADS:
loffice_processes[port_num] = start_office_server(port_num)
port_count += 1
else:
Expand Down

0 comments on commit 057b298

Please sign in to comment.