mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
reduce cpu priority of ffmpeg, hooks, parsers
This commit is contained in:
parent
cc1aaea300
commit
b66843efe2
|
@ -118,7 +118,7 @@ def ffprobe(
|
||||||
b"--",
|
b"--",
|
||||||
fsenc(abspath),
|
fsenc(abspath),
|
||||||
]
|
]
|
||||||
rc, so, se = runcmd(cmd, timeout=timeout)
|
rc, so, se = runcmd(cmd, timeout=timeout, nice=True)
|
||||||
retchk(rc, cmd, se)
|
retchk(rc, cmd, se)
|
||||||
return parse_ffprobe(so)
|
return parse_ffprobe(so)
|
||||||
|
|
||||||
|
@ -562,6 +562,7 @@ class MTag(object):
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
"env": env,
|
"env": env,
|
||||||
|
"nice": True,
|
||||||
"timeout": parser.timeout,
|
"timeout": parser.timeout,
|
||||||
"kill": parser.kill,
|
"kill": parser.kill,
|
||||||
"capture": parser.capture,
|
"capture": parser.capture,
|
||||||
|
@ -572,11 +573,6 @@ class MTag(object):
|
||||||
zd.update(ret)
|
zd.update(ret)
|
||||||
args["sin"] = json.dumps(zd).encode("utf-8", "replace")
|
args["sin"] = json.dumps(zd).encode("utf-8", "replace")
|
||||||
|
|
||||||
if WINDOWS:
|
|
||||||
args["creationflags"] = 0x4000
|
|
||||||
else:
|
|
||||||
cmd = ["nice"] + cmd
|
|
||||||
|
|
||||||
bcmd = [sfsenc(x) for x in cmd[:-1]] + [fsenc(cmd[-1])]
|
bcmd = [sfsenc(x) for x in cmd[:-1]] + [fsenc(cmd[-1])]
|
||||||
rc, v, err = runcmd(bcmd, **args) # type: ignore
|
rc, v, err = runcmd(bcmd, **args) # type: ignore
|
||||||
retchk(rc, bcmd, err, self.log, 5, self.args.mtag_v)
|
retchk(rc, bcmd, err, self.log, 5, self.args.mtag_v)
|
||||||
|
|
|
@ -468,7 +468,7 @@ class ThumbSrv(object):
|
||||||
|
|
||||||
def _run_ff(self, cmd: list[bytes], vn: VFS) -> None:
|
def _run_ff(self, cmd: list[bytes], vn: VFS) -> None:
|
||||||
# self.log((b" ".join(cmd)).decode("utf-8"))
|
# self.log((b" ".join(cmd)).decode("utf-8"))
|
||||||
ret, _, serr = runcmd(cmd, timeout=vn.flags["convt"])
|
ret, _, serr = runcmd(cmd, timeout=vn.flags["convt"], nice=True)
|
||||||
if not ret:
|
if not ret:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -2508,9 +2508,34 @@ def killtree(root: int) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _find_nice() -> str:
|
||||||
|
if WINDOWS:
|
||||||
|
return "" # use creationflags
|
||||||
|
|
||||||
|
try:
|
||||||
|
zs = shutil.which("nice")
|
||||||
|
if zs:
|
||||||
|
return zs
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# busted PATHs and/or py2
|
||||||
|
for zs in ("/bin", "/sbin", "/usr/bin", "/usr/sbin"):
|
||||||
|
zs += "/nice"
|
||||||
|
if os.path.exists(zs):
|
||||||
|
return zs
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
NICES = _find_nice()
|
||||||
|
NICEB = NICES.encode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def runcmd(
|
def runcmd(
|
||||||
argv: Union[list[bytes], list[str]], timeout: Optional[float] = None, **ka: Any
|
argv: Union[list[bytes], list[str]], timeout: Optional[float] = None, **ka: Any
|
||||||
) -> tuple[int, str, str]:
|
) -> tuple[int, str, str]:
|
||||||
|
isbytes = isinstance(argv[0], (bytes, bytearray))
|
||||||
kill = ka.pop("kill", "t") # [t]ree [m]ain [n]one
|
kill = ka.pop("kill", "t") # [t]ree [m]ain [n]one
|
||||||
capture = ka.pop("capture", 3) # 0=none 1=stdout 2=stderr 3=both
|
capture = ka.pop("capture", 3) # 0=none 1=stdout 2=stderr 3=both
|
||||||
|
|
||||||
|
@ -2524,13 +2549,22 @@ def runcmd(
|
||||||
berr: bytes
|
berr: bytes
|
||||||
|
|
||||||
if ANYWIN:
|
if ANYWIN:
|
||||||
if isinstance(argv[0], (bytes, bytearray)):
|
if isbytes:
|
||||||
if argv[0] in CMD_EXEB:
|
if argv[0] in CMD_EXEB:
|
||||||
argv[0] += b".exe"
|
argv[0] += b".exe"
|
||||||
else:
|
else:
|
||||||
if argv[0] in CMD_EXES:
|
if argv[0] in CMD_EXES:
|
||||||
argv[0] += ".exe"
|
argv[0] += ".exe"
|
||||||
|
|
||||||
|
if ka.pop("nice", None):
|
||||||
|
if WINDOWS:
|
||||||
|
ka["creationflags"] = 0x4000
|
||||||
|
elif NICEB:
|
||||||
|
if isbytes:
|
||||||
|
argv = [NICEB] + argv
|
||||||
|
else:
|
||||||
|
argv = [NICES] + argv
|
||||||
|
|
||||||
p = sp.Popen(argv, stdout=cout, stderr=cerr, **ka)
|
p = sp.Popen(argv, stdout=cout, stderr=cerr, **ka)
|
||||||
if not timeout or PY2:
|
if not timeout or PY2:
|
||||||
bout, berr = p.communicate(sin)
|
bout, berr = p.communicate(sin)
|
||||||
|
@ -2678,6 +2712,7 @@ def _parsehook(
|
||||||
|
|
||||||
sp_ka = {
|
sp_ka = {
|
||||||
"env": env,
|
"env": env,
|
||||||
|
"nice": True,
|
||||||
"timeout": tout,
|
"timeout": tout,
|
||||||
"kill": kill,
|
"kill": kill,
|
||||||
"capture": cap,
|
"capture": cap,
|
||||||
|
|
Loading…
Reference in a new issue