Fixed multiple awatches.

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2024-05-12 13:07:06 +02:00
parent 0ca224fe50
commit 5419ec0bf1

View File

@ -9,16 +9,6 @@ from anime import dtos
router = APIRouter()
def is_pid_alive(pid: int) -> bool:
if pid:
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True
@router.get("/can-start-watching")
def can_start_watching(request: Request) -> None:
if not request.app.state.anime_dir:
@ -39,8 +29,17 @@ def start_watching(request: Request) -> None:
awatch = shutil.which("awatch")
if awatch is None:
raise Exception("awatch command is not available")
ret = subprocess.Popen(
pidof = subprocess.Popen(
["pidof", "awatch"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
if pidof.wait() == 0:
raise HTTPException(status_code=400, detail="awatch is already running")
subprocess.Popen(
[awatch],
cwd=anime_dir,
shell=True,
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
)
request.app.state.pid = ret.pid