mirror of https://github.com/CIRCL/PyCIRCLean
Change _run_process() to use builtin timeout parameter
NOTE: this change breaks Python 2 compatability: subprocess.check_call does not take a timeout argument in Python 2.7pull/8/head
parent
573cf51b69
commit
fd30fb3e08
|
@ -4,7 +4,6 @@ import os
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
import oletools.oleid
|
import oletools.oleid
|
||||||
|
@ -206,27 +205,14 @@ class KittenGroomerFileCheck(KittenGroomerBase):
|
||||||
else:
|
else:
|
||||||
tmp_log.debug(self.cur_file.log_string)
|
tmp_log.debug(self.cur_file.log_string)
|
||||||
|
|
||||||
def _run_process(self, command_string, timeout=0, background=False):
|
def _run_process(self, command_string, timeout=None):
|
||||||
"""Run command_string in a subprocess, wait until it finishes."""
|
"""Run command_string in a subprocess, wait until it finishes."""
|
||||||
if timeout != 0:
|
|
||||||
deadline = time.time() + timeout
|
|
||||||
else:
|
|
||||||
deadline = None
|
|
||||||
args = shlex.split(command_string)
|
args = shlex.split(command_string)
|
||||||
with open(self.log_debug_err, 'ab') as stderr, open(self.log_debug_out, 'ab') as stdout:
|
with open(self.log_debug_err, 'ab') as stderr, open(self.log_debug_out, 'ab') as stdout:
|
||||||
p = subprocess.Popen(args, stdout=stdout, stderr=stderr)
|
try:
|
||||||
if background:
|
subprocess.check_call(args, stdout=stdout, stderr=stderr, timeout=timeout)
|
||||||
# This timer is here to make sure the unoconv listener is properly started.
|
except (subprocess.TimeoutExpired, subprocess.CalledProcessError):
|
||||||
time.sleep(10)
|
return
|
||||||
return True
|
|
||||||
while True:
|
|
||||||
code = p.poll()
|
|
||||||
if code is not None:
|
|
||||||
break
|
|
||||||
if deadline is not None and time.time() > deadline:
|
|
||||||
p.kill()
|
|
||||||
break
|
|
||||||
time.sleep(1)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
|
|
Loading…
Reference in New Issue