Skip to content

Commit 8c276ac

Browse files
committed
Lazy filelock import
1 parent 175b67b commit 8c276ac

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pytensor/compile/compilelock.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from contextlib import contextmanager
99
from pathlib import Path
1010

11-
import filelock
12-
1311
from pytensor.configdefaults import config
1412

1513

@@ -35,8 +33,9 @@ def force_unlock(lock_dir: os.PathLike):
3533
lock_dir : os.PathLike
3634
Path to a directory that was locked with `lock_ctx`.
3735
"""
36+
from filelock import FileLock
3837

39-
fl = filelock.FileLock(Path(lock_dir) / ".lock")
38+
fl = FileLock(Path(lock_dir) / ".lock")
4039
fl.release(force=True)
4140

4241
dir_key = f"{lock_dir}-{os.getpid()}"
@@ -62,6 +61,8 @@ def lock_ctx(
6261
Timeout in seconds for waiting in lock acquisition.
6362
Defaults to `pytensor.config.compile__timeout`.
6463
"""
64+
from filelock import FileLock
65+
6566
if lock_dir is None:
6667
lock_dir = config.compiledir
6768

@@ -73,7 +74,7 @@ def lock_ctx(
7374

7475
if dir_key not in local_mem._locks:
7576
local_mem._locks[dir_key] = True
76-
fl = filelock.FileLock(Path(lock_dir) / ".lock")
77+
fl = FileLock(Path(lock_dir) / ".lock")
7778
fl.acquire(timeout=timeout)
7879
try:
7980
yield

0 commit comments

Comments
 (0)