From 207c03f2d047e531377c8c301b4de4a22963aec7 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Thu, 7 Nov 2024 08:24:44 -0500 Subject: [PATCH] fix windows --- src/witty/compile_module.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/witty/compile_module.py b/src/witty/compile_module.py index e20f1e4..761c362 100644 --- a/src/witty/compile_module.py +++ b/src/witty/compile_module.py @@ -1,3 +1,4 @@ +import os import Cython import fcntl import hashlib @@ -115,8 +116,8 @@ def compile_module( module_dir.mkdir(parents=True, exist_ok=True) # make sure the same module is not build concurrently - with open(module_lock, "w") as lock_file: - fcntl.lockf(lock_file, fcntl.LOCK_EX) + with open(module_lock, "w") as lock_f: + lock_file(lock_f) # already compiled? if module_lib.is_file() and not force_rebuild: @@ -146,3 +147,22 @@ def compile_module( build_extension.run() return load_dynamic(module_name, module_lib) + + +if os.name == "nt": + import msvcrt + + def lock_file(file): + msvcrt.locking(file.fileno(), msvcrt.LK_LOCK, os.path.getsize(file.name)) + + def unlock_file(file): + msvcrt.locking(file.fileno(), msvcrt.LK_UNLCK, os.path.getsize(file.name)) + +else: + import fcntl + + def lock_file(file): + fcntl.lockf(file, fcntl.LOCK_EX) + + def unlock_file(file): + fcntl.lockf(file, fcntl.LOCK_UN)