Skip to content

Commit

Permalink
replace fcntl lib to portalocker
Browse files Browse the repository at this point in the history
  • Loading branch information
Josephine.Rutten committed Oct 7, 2024
1 parent c80703b commit 10f2f1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 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
6 changes: 3 additions & 3 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,7 +36,7 @@ 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)
portalocker.Lock(self.lock_f, flags=portalocker.LOCK_EX | portalocker.LOCK_NB)
except BlockingIOError:
try:
import uwsgi # noqa: F401
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 10f2f1a

Please sign in to comment.