Skip to content

Commit f42ac75

Browse files
committed
Additional fixes to port map file.
1 parent 3dcc35f commit f42ac75

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
from sys import platform
55

6-
OCR_SERVICE_VERSION = "0.2.0"
6+
OCR_SERVICE_VERSION = "0.2.3"
77
# 50 - CRITICAL, 40 - ERROR, 30 - WARNING, 20 - INFO, 10 - DEBUG, 0 - NOTSET
88
LOG_LEVEL = int(os.environ.get("OCR_SERVICE_LOG_LEVEL", 40))
99

1010
ROOT_DIR = os.path.abspath(os.curdir)
1111
TMP_FILE_DIR = os.path.join(ROOT_DIR, "tmp")
1212

1313
# Should we actually ocr or just extract text from PDFs ? NOTE: OCR IS STILL APPLIED TO IMAGES if detected | possible vals : "OCR", "NO_OCR"
14-
OPERATION_MODE= os.environ.get("OCR_SERVICE_OPERATION_MODE", "OCR")
14+
OPERATION_MODE = os.environ.get("OCR_SERVICE_OPERATION_MODE", "OCR")
1515

1616
# basic app settings
1717
OCR_SERVICE_PORT = os.environ.get("OCR_SERVICE_PORT", 8090)

gunicorn.conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def pre_fork(server, worker):
1212
global counter
1313

14-
time.sleep(2 + counter * 1.5)
14+
time.sleep(1 + counter)
1515
counter += 1
1616

1717
def post_fork(server, worker):

ocr_service/app/app.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ def start_office_converter_servers():
3030
port_count = 0
3131

3232
for port_num in LIBRE_OFFICE_LISTENER_PORT_RANGE:
33-
if (port_count < OCR_WEB_SERVICE_WORKERS or port_count < OCR_WEB_SERVICE_THREADS):
34-
port_count += 1
33+
if port_num == get_assigned_port(os.getpid()) and OCR_WEB_SERVICE_THREADS == 1:
3534
print("STARTED WORKER ON PORT: " + str(port_num))
3635
process = start_office_server(port_num)
3736
loffice_processes[port_num] = process
38-
if port_num == get_assigned_port(os.getpid()) and OCR_WEB_SERVICE_THREADS == 1:
39-
break
40-
elif OCR_WEB_SERVICE_WORKERS == 1:
41-
continue
37+
break
38+
elif OCR_WEB_SERVICE_WORKERS == 1 and OCR_WEB_SERVICE_THREADS > 1:
39+
process = start_office_server(port_num)
40+
loffice_processes[port_num] = process
4241

4342
return loffice_processes
4443

ocr_service/utils/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ def get_process_id_by_process_name(process_name: str = "") -> int:
9999
return pid
100100

101101
def sync_port_mapping(worker_id = None, worker_pid = None):
102-
with open(os.path.join(TMP_FILE_DIR, './worker_process_data.txt'), encoding="utf-8", mode='a+') as f:
102+
103+
104+
f_path = os.path.join(TMP_FILE_DIR, './worker_process_data.txt')
105+
open_mode = "r+"
106+
if not os.path.exists(f_path):
107+
open_mode = "w+"
108+
109+
with open(f_path, encoding="utf-8", mode=open_mode) as f:
103110
fcntl.lockf(f, fcntl.LOCK_EX)
104111

105112
port_mapping = {}

0 commit comments

Comments
 (0)