Public Access
19 lines
602 B
Python
19 lines
602 B
Python
"""One managed temporary Minecraft server at a time on this host."""
|
|
from contextlib import contextmanager
|
|
import fcntl
|
|
from pathlib import Path
|
|
import tempfile
|
|
|
|
|
|
@contextmanager
|
|
def server_test_lock():
|
|
with (Path(tempfile.gettempdir()) / "rivencraft-server-tests.lock").open("a") as lock:
|
|
try:
|
|
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
except BlockingIOError:
|
|
raise SystemExit("Another Rivencraft server test is active; finish it before starting this one")
|
|
try:
|
|
yield
|
|
finally:
|
|
fcntl.flock(lock, fcntl.LOCK_UN)
|