Skip to content

Commit

Permalink
fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Nov 7, 2024
1 parent 33fdc70 commit 207c03f
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/witty/compile_module.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import Cython
import fcntl
import hashlib
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit 207c03f

Please sign in to comment.