add disable lock flags

This commit is contained in:
Dun Liang 2021-12-28 12:59:43 +08:00
parent 8c44329def
commit 3a31e32a1a
3 changed files with 11 additions and 1 deletions

View File

@ -9,7 +9,7 @@
# file 'LICENSE.txt', which is part of this source code package.
# ***************************************************************
__version__ = '1.3.1.29'
__version__ = '1.3.1.30'
from jittor_utils import lock
with lock.lock_scope():
ori_int = int

View File

@ -28,6 +28,8 @@ namespace jittor {
static int lock_fd = -1;
int _has_lock = 0;
DEFINE_FLAG(bool, disable_lock, 0, "Disable file lock");
void set_lock_path(string path) {
lock_fd = open(path.c_str(), O_RDWR);
ASSERT(lock_fd >= 0);
@ -35,6 +37,7 @@ void set_lock_path(string path) {
}
void lock() {
if (disable_lock) return;
ASSERT(lock_fd >= 0);
#ifdef _WIN32
OVERLAPPED offset = {0, 0, 0, 0, NULL};
@ -54,6 +57,7 @@ void lock() {
}
void unlock() {
if (disable_lock) return;
ASSERT(lock_fd >= 0);
#ifdef _WIN32
OVERLAPPED offset = {0, 0, 0, 0, NULL};

View File

@ -14,6 +14,8 @@ If conda is used, please install with command:
import os
from jittor_utils import cache_path, LOG
disable_lock = os.environ.get("disable_lock", "0") == "1"
class Lock:
def __init__(self, filename):
self.handle = open(filename, 'w')
@ -21,6 +23,8 @@ class Lock:
self.is_locked = False
def lock(self):
if disable_lock:
return
if fcntl:
fcntl.flock(self.handle, fcntl.LOCK_EX)
else:
@ -30,6 +34,8 @@ class Lock:
LOG.vv(f'LOCK PID: {os.getpid()}')
def unlock(self):
if disable_lock:
return
if fcntl:
fcntl.flock(self.handle, fcntl.LOCK_UN)
else: