OpenSolaris derivate (NexentaStor), python 2.5.5
我见过很多例子,很多例子似乎表明问题是僵局。我不是写stdin所以我认为问题是其中一个shell命令过早退出。
Popen执行的是:
ssh <remotehost> "zfs send tank/dataset@snapshot | gzip -9" | gzip -d | zfs recv tank/dataset
换句话说,登录到远程主机并(发送存储卷的复制流,将其传输到gzip)将其传输到zfs recv以写入本地数据存储。
我已经看到了关于缓冲区的解释,但是我肯定没有填写那些,并且gzip过早地淘汰了所以我认为process.wait()永远不会退出。
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
process.wait()
if process.returncode == 0:
for line in process.stdout:
stdout_arr.append([line])
return stdout_arr
else:
return False
这是我跑步和打断时发生的事情
# ./zfs_replication.py
gzip: stdout: Broken pipe
^CKilled by signal 2.
Traceback (most recent call last):
File "./zfs_replication.py", line 155, in <module>
Exec(zfsSendRecv(dataset, today), LOCAL)
File "./zfs_replication.py", line 83, in Exec
process.wait()
File "/usr/lib/python2.5/subprocess.py", line 1184, in wait
pid, sts = self._waitpid_no_intr(self.pid, 0)
File "/usr/lib/python2.5/subprocess.py", line 1014, in _waitpid_no_intr
return os.waitpid(pid, options)
KeyboardInterrupt
我也尝试使用Popen.communicat()方法,但是如果gzip拯救,它也会挂起。在这种情况下,我的命令的最后一部分(zfs recv)退出,因为本地数据集已被修改,因此将不会应用增量复制流,所以即使这将被修复,也必须有一种处理gzips破解的方法管?
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode == 0:
dosomething()
else:
dosomethingelse()
跑步时:
cannot receive incremental stream: destination tank/repl_test has been modified
since most recent snapshot
gzip: stdout: Broken pipe
^CKilled by signal 2.Traceback (most recent call last):
File "./zfs_replication.py", line 154, in <module>
Exec(zfsSendRecv(dataset, today), LOCAL)
File "./zfs_replication.py", line 83, in Exec
stdout, stderr = process.communicate()
File "/usr/lib/python2.5/subprocess.py", line 662, in communicate
stdout = self._fo_read_no_intr(self.stdout)
File "/usr/lib/python2.5/subprocess.py", line 1025, in _fo_read_no_intr
return obj.read()
KeyboardInterrupt