MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / subproc_call

Function subproc_call

tensorpack/utils/concurrency.py:243–272  ·  view source on GitHub ↗

Execute a command with timeout, and return STDOUT and STDERR Args: cmd(str): the command to execute. timeout(float): timeout in seconds. Returns: output(bytes), retcode(int). If timeout, retcode is -1.

(cmd, timeout=None)

Source from the content-addressed store, hash-verified

241
242
243def subproc_call(cmd, timeout=None):
244 """
245 Execute a command with timeout, and return STDOUT and STDERR
246
247 Args:
248 cmd(str): the command to execute.
249 timeout(float): timeout in seconds.
250
251 Returns:
252 output(bytes), retcode(int). If timeout, retcode is -1.
253 """
254 try:
255 output = subprocess.check_output(
256 cmd, stderr=subprocess.STDOUT,
257 shell=True, timeout=timeout)
258 return output, 0
259 except subprocess.TimeoutExpired as e:
260 logger.warn("Command '{}' timeout!".format(cmd))
261 if e.output:
262 logger.warn(e.output.decode('utf-8'))
263 return e.output, -1
264 else:
265 return "", -1
266 except subprocess.CalledProcessError as e:
267 logger.warn("Command '{}' failed, return code={}".format(cmd, e.returncode))
268 logger.warn(e.output.decode('utf-8'))
269 return e.output, e.returncode
270 except Exception:
271 logger.warn("Command '{}' failed to run.".format(cmd))
272 return "", -2
273
274
275class OrderedContainer(object):

Callers 4

get_caffe_pbFunction · 0.85
_use_ldFunction · 0.85
_use_ldconfigFunction · 0.85
get_num_gpuFunction · 0.85

Calls 1

formatMethod · 0.80

Tested by

no test coverage detected