@ -9,16 +9,6 @@ from anime import dtos
|
|||||||
router = APIRouter()
|
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")
|
@router.get("/can-start-watching")
|
||||||
def can_start_watching(request: Request) -> None:
|
def can_start_watching(request: Request) -> None:
|
||||||
if not request.app.state.anime_dir:
|
if not request.app.state.anime_dir:
|
||||||
@ -39,8 +29,17 @@ def start_watching(request: Request) -> None:
|
|||||||
awatch = shutil.which("awatch")
|
awatch = shutil.which("awatch")
|
||||||
if awatch is None:
|
if awatch is None:
|
||||||
raise Exception("awatch command is not available")
|
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],
|
[awatch],
|
||||||
cwd=anime_dir,
|
cwd=anime_dir,
|
||||||
|
shell=True,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
)
|
)
|
||||||
request.app.state.pid = ret.pid
|
|
||||||
|
Reference in New Issue
Block a user