diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 8520d3d0..c28d2e83 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -8,7 +8,7 @@ import threading import subprocess as sp from .__init__ import PY2 -from .util import fsenc, Queue, Cooldown, BytesIO +from .util import fsenc, mchkcmd, Queue, Cooldown, BytesIO from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, ffprobe @@ -299,8 +299,7 @@ class ThumbSrv(object): cmd += [fsenc(tpath)] - p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE) - p.communicate() + mchkcmd(*cmd) def poke(self, tdir): if not self.poke_cd.poke(tdir): diff --git a/copyparty/util.py b/copyparty/util.py index 37971732..697aa5b6 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -985,6 +985,17 @@ def chkcmd(*argv): return sout, serr +def mchkcmd(*argv, timeout=10): + if PY2: + with open(os.devnull, "wb") as f: + rv = sp.call(argv, stdout=f, stderr=f) + else: + rv = sp.call(argv, stdout=sp.DEVNULL, stderr=sp.DEVNULL, timeout=timeout) + + if rv: + raise sp.CalledProcessError(rv, (argv[0], b"...", argv[-1])) + + def gzip_orig_sz(fn): with open(fsenc(fn), "rb") as f: f.seek(-4, 2)