You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
642 B
30 lines
642 B
import os |
|
|
|
LOCK_DIR = "/var/lib/otbcloud/locks" |
|
|
|
def _lock_path(name): |
|
return os.path.join(LOCK_DIR, f"{name}.lock") |
|
|
|
def is_locked(name): |
|
return os.path.exists(_lock_path(name)) |
|
|
|
def acquire(name): |
|
os.makedirs(LOCK_DIR, exist_ok=True) |
|
path = _lock_path(name) |
|
if os.path.exists(path): |
|
return False |
|
with open(path, "w") as f: |
|
f.write(str(os.getpid())) |
|
return True |
|
|
|
def release(name): |
|
path = _lock_path(name) |
|
if os.path.exists(path): |
|
os.remove(path) |
|
|
|
def select_processor(): |
|
if acquire("intel"): |
|
return "intel" |
|
if acquire("amd"): |
|
return "amd" |
|
return "cpu"
|
|
|