Skip to content

Commit 3dc6dfc

Browse files
author
Pierre-Luc Tessier Gagné
committed
Adding dummy file lock when importing FileLock fails
1 parent c2e767b commit 3dc6dfc

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import tempfile
1616
from collections import deque
1717

18-
from filelock import FileLock
19-
2018
from can import Message, CanError, BusABC
2119

2220
logger = logging.getLogger(__name__)
@@ -32,6 +30,30 @@
3230
ics = None
3331

3432

33+
try:
34+
from filelock import FileLock
35+
except ImportError as ie:
36+
37+
logger.warning(
38+
"Using ICS NeoVi can backend without the "
39+
"filelock module installed may cause some issues!: %s",
40+
ie,
41+
)
42+
43+
class FileLock:
44+
"""Dummy file lock that do not actually do anything"""
45+
46+
def __init__(self, lock_file, timeout=-1):
47+
self._lock_file = lock_file
48+
self.timeout = timeout
49+
50+
def __enter__(self):
51+
return self
52+
53+
def __exit__(self, exc_type, exc_val, exc_tb):
54+
return None
55+
56+
3557
# Use inter-process mutex to prevent concurrent device open.
3658
# When neoVI server is enabled, there is an issue with concurrent device open.
3759
open_lock = FileLock(os.path.join(tempfile.gettempdir(), "neovi.lock"))

0 commit comments

Comments
 (0)