def rm(filename, sudo=False):
"""
Remove a file on the disk, not us os.rm because we want to add timeout to
the command. It's possible that the os call got hang when the disk has
some problems
"""
cmd_args = []
if sudo:
cmd_args += ['sudo']
cmd_args += ['/bin/rm', filename]
log.debug("Executing cmd: {}".format(str(cmd_args)))
proc = subprocess.Popen(cmd_args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
try:
(stdout, stderr) = proc.communicate(timeout=10)
except subprocess.TimeoutExpired:
proc.kill()
raise OSCError('SHELL_TIMEOUT', {'cmd': ' '.join(cmd_args)})
评论列表
文章目录