Skip to content

Commit 799cf02

Browse files
author
Pierre-Luc Tessier Gagné
committed
Use inter-process mutex to prevent concurrent neoVI device open
When neoVI server is enabled, there is an issue with concurrent device open.
1 parent 55a4396 commit 799cf02

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
"""
1212

1313
import logging
14+
import os
15+
import tempfile
1416
from collections import deque
1517

1618
from can import Message, CanError, BusABC
19+
from filelock import FileLock
1720

1821
logger = logging.getLogger(__name__)
1922

@@ -122,7 +125,14 @@ def __init__(self, channel, can_filters=None, **kwargs):
122125
type_filter = kwargs.get("type_filter")
123126
serial = kwargs.get("serial")
124127
self.dev = self._find_device(type_filter, serial)
125-
ics.open_device(self.dev)
128+
129+
# Use inter-process mutex to prevent concurrent device open.
130+
# When neoVI server is enabled, there is an issue with concurrent
131+
# device open.
132+
open_lock = FileLock(
133+
os.path.join(tempfile.gettempdir(), 'neovi.lock'))
134+
with open_lock:
135+
ics.open_device(self.dev)
126136

127137
if "bitrate" in kwargs:
128138
for channel in self.channels:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"wrapt~=1.10",
9191
"aenum",
9292
'windows-curses;platform_system=="Windows"',
93+
'filelock'
9394
],
9495
setup_requires=["pytest-runner"],
9596
extras_require=extras_require,

0 commit comments

Comments
 (0)