From 3922a7c64b97e24b1fe3a293f720ea27c1406862 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 19 Jan 2018 07:58:58 +0000 Subject: [PATCH] artiq_devtool: make locking reentrant. --- artiq/frontend/artiq_devtool.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/artiq/frontend/artiq_devtool.py b/artiq/frontend/artiq_devtool.py index 02ac2c211..c4c230ff4 100755 --- a/artiq/frontend/artiq_devtool.py +++ b/artiq/frontend/artiq_devtool.py @@ -13,6 +13,7 @@ import select import threading import os import shutil +import re from artiq.tools import verbosity_args, init_logger, logger, SSHClient @@ -93,6 +94,15 @@ def main(): nonlocal flock_file if not flock_acquired: + fuser_args = ["fuser", "-u", lockfile] + fuser = client.spawn_command(fuser_args) + fuser_file = fuser.makefile('r') + fuser_match = re.search(r"\((.+?)\)", fuser_file.readline()) + if fuser_match.group(1) == os.getenv("USER"): + logger.info("Lock already acquired by {}".format(os.getenv("USER"))) + flock_acquired = True + return + logger.info("Acquiring device lock") flock_args = ["flock"] if not args.wait: