Descriptor leak in python 2.4 subprocess module

Discussion in 'Python' started by Michel Lespinasse, Aug 28, 2008.

  1. Hi,

    I hit an issue with the following python code:

    try:
    get_orient = subprocess.Popen (['jpegexiforient', '-n', pathfull],
    stdin = subprocess.PIPE,
    stdout = subprocess.PIPE)
    orient = get_orient.communicate ()[0]
    except:
    orient = None

    The intent of this was to read the exif orientation of a picture, or just
    use None if jpegexiforient can not run.

    The application worked fine on my devel machine but I noticed that on a
    different host, it crashed due to running out of file descriptors.
    After investigation I found out that the above code was responsible,
    leaking two file descriptors per invocation if jpegexiforient is not
    installed on the host.

    I don't see any way to fix it in my code either, since get_orient is not
    defined in the exception path, there is no way I can close its file
    descriptors myself. I believe this is a bug in the subprocess module,
    it should make sure to clean up after itself when getting out on the
    exception path.

    This is with python 2.4.4 on linux (debian etch distribution).

    Hope this helps. I would prefer to be copied in any replies as I'm not
    on the list (I will notice the replies after a while either way, but
    it'll be faster if you can copy me).

    Cheers,

    --
    Michel "Walken" Lespinasse
    A program is never fully debugged until the last user dies.
     
    Michel Lespinasse, Aug 28, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. albright
    Replies:
    5
    Views:
    6,147
    Tim Ward
    Dec 16, 2004
  2. kj.kjn
    Replies:
    2
    Views:
    335
    Pierre Schnizer
    Jul 3, 2003
  3. Steve Quezadas

    Can subprocess point to file descriptor 5?

    Steve Quezadas, May 3, 2006, in forum: Python
    Replies:
    1
    Views:
    574
    Diez B. Roggisch
    May 3, 2006
  4. Richard Heathfield

    Leak or no leak ??

    Richard Heathfield, Jul 10, 2006, in forum: C Programming
    Replies:
    4
    Views:
    376
    Richard Heathfield
    Jul 10, 2006
  5. hiral
    Replies:
    2
    Views:
    627
    Jean-Michel Pichavant
    May 5, 2010
Loading...

Share This Page