diff --git a/requirements.txt b/requirements.txt index 0640c812..0f0b134b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,3 +36,4 @@ greenlet==3.0.3 pydantic_settings==2.4.0 Authlib==1.3.1 python-jose==3.3.0 +portalocker==2.8.2 diff --git a/src/cnaas_nms/scheduler/scheduler.py b/src/cnaas_nms/scheduler/scheduler.py index a671b242..ac4e5cbe 100644 --- a/src/cnaas_nms/scheduler/scheduler.py +++ b/src/cnaas_nms/scheduler/scheduler.py @@ -1,11 +1,11 @@ import datetime -import fcntl import inspect import json import os from types import FunctionType from typing import Optional, Union +import portalocker from apscheduler.executors.pool import ThreadPoolExecutor from apscheduler.jobstores.memory import MemoryJobStore from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore @@ -36,8 +36,8 @@ def __init__(self): # If scheduler is already started, use uwsgi ipc to send job to mule process self.lock_f = open("/tmp/scheduler.lock", "w") try: - fcntl.lockf(self.lock_f, fcntl.LOCK_EX | fcntl.LOCK_NB) - except BlockingIOError: + portalocker.lock(self.lock_f, flags=portalocker.LOCK_EX | portalocker.LOCK_NB) + except portalocker.exceptions.LockException: try: import uwsgi # noqa: F401 except Exception: @@ -80,7 +80,7 @@ def __init__(self): def __del__(self): if self.lock_f: - fcntl.lockf(self.lock_f, fcntl.LOCK_UN) + portalocker.unlock(self.lock_f) self.lock_f.close() os.unlink("/tmp/scheduler.lock")