Skip to content

Commit

Permalink
Replace fcntl lib to portalocker (#371)
Browse files Browse the repository at this point in the history
* replace fcntl lib to portalocker

* replace the fcntl locker with portalocker to make os independent

---------

Co-authored-by: Josephine.Rutten <[email protected]>
  • Loading branch information
Josephine-Rutten and Josephine.Rutten authored Oct 21, 2024
1 parent fa235d7 commit 7c4df23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/cnaas_nms/scheduler/scheduler.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 7c4df23

Please sign in to comment.