Skip to content

Commit 63e3dca

Browse files
authored
Merge pull request #93 from blues/devin/1738266464-filelock-config
feat: make FileLock path configurable
2 parents 342adfc + 3b67a78 commit 63e3dca

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

notecard/notecard.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,25 @@ def unlock(self):
574574
"""Unlock access to the serial bus."""
575575
self.lock_handle.release()
576576

577-
def __init__(self, uart_id, debug=False):
578-
"""Initialize the Notecard before a reset."""
577+
def __init__(self, uart_id, debug=False, lock_path=None):
578+
"""Initialize the Notecard before a reset.
579+
580+
Args:
581+
uart_id: The serial port identifier.
582+
debug: Enable debug output if True.
583+
lock_path: Optional path for the serial lock file. Defaults to /tmp/serial.lock
584+
or the value of NOTECARD_SERIAL_LOCK_PATH environment variable.
585+
"""
579586
super().__init__(debug)
580587
self._user_agent['req_interface'] = 'serial'
581588
self._user_agent['req_port'] = str(uart_id)
582589

583590
self.uart = uart_id
584591

585592
if use_serial_lock:
586-
self.lock_handle = FileLock('serial.lock')
593+
if lock_path is None:
594+
lock_path = os.environ.get('NOTECARD_SERIAL_LOCK_PATH', '/tmp/serial.lock')
595+
self.lock_handle = FileLock(lock_path)
587596
else:
588597
self.lock_handle = NoOpSerialLock()
589598

0 commit comments

Comments
 (0)