主程序调用外部程序mysqldump备份数据库,代码如下:
try:
with gzip.open(bakfilname, "wb") as f:
p1 = subprocess.Popen(mysqldump + " -h %s --port %s -u %s -p%s %s --databases %s " % (pol_ip, pol_port, str_user, str_passwd, str_bk_options, str_schemas), stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
f.writelines(p1.stdout)
output = p1.stderr.read()
if output == '':
log("OK")
else:
log(output)
exit(1)
except subprocess.CalledProcessError as e:
print("Error: process exited with status %s" % e.returncode)
期间主程序界面hang住,需要等待备份执行完。如果数据库比较大,等待时间很长。我现在需要不要等待,发出执行命令后,主程序依然可以做其它操作。
请问这个需求怎么实现?