最开始启动一个进程:
1:p = create_multiprocess(target=getsmoketest, args=[intranetip, username, password]) def create_multiprocess(target, args=()): p = multiprocessing.Process(target=target, args=args) p.start() return p 2script_path = os.path.join(BASE_DIR, "common/smoketestreport/runsmoketestcases.sh") args = ["sh", "-x", script_path, self.ip, self.user, self.password, BASE_DIR] exit_value = 1 try: process = subprocess.Popen(args, bufsize=1, stdout=subprocess.PIPE, close_fds=True, preexec_fn=os.setsid, universal_newlines=True) while process.poll() is None: out_put_log = process.stdout.readline() self.logger.output_shelllog_to_logger(out_put_log) process.wait() exit_value = process.returncode except Exception, e: self.logger.error(e.message) if exit_value != 0: err_msg = "[DevOps_Error]:Execute " + script_path + " error!!!" self.logger.error(err_msg) return self.EXCEPTION return self.NORMAL 这样算是开始执行脚本了,但是在shell脚本有个问题: 1脚本要识别这个Django框架路径,也就是用到了BASE_DIR这个路径 2在shell脚本开启spawn的时候,最好设置set timeout -1这句话 代码: /usr/bin/expect <