Using os.popen3() to get binary data

Christoph Krammer redtiger84 at
Fri Apr 6 13:02:52 CEST 2007

Hello everybody,

I need to get the different frames from a GIF image in my python
script and want to use the giftopnm program from netpbm to get the
frames and directly convert them to pnm files. I tried to use the
following code:

for image in images:
    if (image[0:3] == 'GIF'):
      (si, so, se) = os.popen3('giftopnm -image=all', 'b')
      frame = so.readlines()

But with this code the script just hangs. When I interrupt the script,
I get the following error message:
Traceback (most recent call last):
  File "/home/tiger/stock-spam/scripts/", line 46, in ?
    frames = so.readlines()
close failed: [Errno 32] Broken pipe

Can somebody tell me, which command I have to use that the pipe will
be closed when the giftopnm returns? This program just prints the
converted images to stdout and terminates.

Thanks in advance,

More information about the Python-list mailing list