[英]Python subprocess call hungs when running rpm2cpio
I'm running the below command using python subprocess to extract files from rpm. 我正在使用python子进程运行以下命令以从rpm提取文件。 But the command failes when the rpm size is more than 25 - 30 MB.
但是,当rpm大小大于25-30 MB时,该命令将失败。 Tried the command using
Popen
, call
, with stdout
as PIPE
and os.system
as well. 使用
Popen
, call
以及stdout
作为PIPE
和os.system
对命令进行了尝试。 This command is working fine when i run it in shell directly. 当我直接在shell中运行该命令时,它运行良好。 The problem is only when i invoke this by some means from Python
问题只有当我以某种方式从Python调用它时
Command: 命令:
rpm2cpio <rpm_name>.rpm| cpio -idmv
I did an strace on the process id and found that its always hung on some write system call 我对进程ID进行了跟踪,发现它总是挂在某些写入系统调用上
ps -ef | grep cpio
root 4699 4698 4 11:05 pts/0 00:00:00 rpm2cpio kernel-2.6.32-573.26.1.el6.x86_64.rpm
root 4700 4698 0 11:05 pts/0 00:00:00 cpio -idmv
strace -p 4699
Process 4699 attached
write(10, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0rc_pixelview_new"..., 8192
strace -p 4700
Process 4700 attached
write(2, "./lib/modules/2.6.32-573.26.1.el"..., 94
I have 2 questions: 我有两个问题:
If all you want is the payload of a *.rpm package, then do the computations to find the beginning of the compressed cpio payload and do the operations directly in python. 如果只需要* .rpm软件包的有效负载,则可以进行计算以找到压缩的cpio有效负载的开头,然后直接在python中进行操作。
See How do I extract the contents of an rpm? 请参阅如何提取rpm的内容? for a rpm2cpio.sh shell script that documents the necessary computations.
用于记录必需的计算的rpm2cpio.sh Shell脚本。 The only subtlety is ensuring that the padding (needed for alignment) between the signature and metadata headers is correct.
唯一的妙处是确保签名和元数据标头之间的填充(对齐所需)正确。
Your output pipe is full. 您的输出管道已满。 The python docs note in many places not to do what you are doing:
在python文档注意到,在许多地方, 不要做你正在做的事情:
Do not use stdout=PIPE or stderr=PIPE with this function as that can deadlock based on the child process output volume.
请勿将stdout = PIPE或stderr = PIPE与此功能一起使用,因为这可能会基于子进程的输出量而死锁。 Use Popen with the communicate() method when you need pipes.
需要管道时,可以将Popen与communication()方法一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.