tempfile.mkstemp problem?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marco

    tempfile.mkstemp problem?


    Hello,

    I having a problem creating directories with Python 2.3.4
    (compiled with gcc 3.2.2, under Linux 2.4.20-31.9).

    I'm writing a plugin which works in the following way:

    GUI -- talks to --> Perl backend
    Perl backend -- talks to --> Python plugin
    Python plugin -- talks to --> Python script

    I can see the exact command the Python plugin uses to
    call the Python script (e.g. "foo.py -o file -w dir arg2")

    When I run the command from the GUI I get the follwing
    error:

    Traceback (most recent call last):
    File "/home/marco/bin/ogm_encoder.py" , line 652, in ?
    do_encode()
    File "/home/marco/bin/ogm_encoder.py" , line 333, in do_encode
    mpegv = tempfile.mkstem p('.mpv', '', work_dir)[1]
    File "/usr/lib/python2.3/tempfile.py", line 282, in mkstemp
    return _mkstemp_inner( dir, prefix, suffix, flags)
    File "/usr/lib/python2.3/tempfile.py", line 216, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
    OSError: [Errno 13] Permission denied: '/tmp/991319584/metd/3vYjxJ.mpv'

    However, if I run the Python script using the exact same
    parameters which it gets from the GUI and in the same
    directory everything works fine, temp files and dirs
    are created OK.

    I first create the dir as follows:

    work_dir = opts.get('-w', img_dir)
    work_dir = os.path.abspath (work_dir)
    if not os.path.isdir(w ork_dir):
    if not quiet: print 'Creating ' + work_dir
    try:
    os.makedirs(wor k_dir)
    except:
    print 'Could not create the work directory ' + \
    work_dir
    raise SystemExit

    This works fine. To make sure, I even added a check right
    before making the tempfile:

    print os.path.isdir('/tmp/991319584/metd/')
    mpegv = tempfile.mkstem p('.mpv', '', work_dir)[1]

    The "os.path.is dir" says "True". Here's the kicker:
    after the tempfile.mkstem p error, the "metd" directory
    disappears! It's deleted!

    So, running the Python script on its own creates the
    temp file OK, no problem, but when I call is from the


    --
    marco@reimeika. ca
    Gunnm: Broken Angel http://amv.reimeika.ca
    http://reimeika.ca/ http://photo.reimeika.ca
  • marco

    #2
    Re: tempfile.mkstem p problem?


    The last one! For real!

    marco <marco@reimeika .ca> writes:
    [color=blue]
    > I first create the dir as follows:
    >
    > work_dir = opts.get('-w', img_dir)
    > work_dir = os.path.abspath (work_dir)
    > if not os.path.isdir(w ork_dir):
    > if not quiet: print 'Creating ' + work_dir
    > try:
    > os.makedirs(wor k_dir)
    > except:
    > print 'Could not create the work directory ' + \
    > work_dir
    > raise SystemExit
    >
    > This works fine. To make sure, I even added a check right
    > before making the tempfile:
    >
    > print os.path.isdir('/tmp/991319584/metd/')
    > mpegv = tempfile.mkstem p('.mpv', '', work_dir)[1]
    >
    > The "os.path.is dir" says "True". Here's the kicker:
    > after the tempfile.mkstem p error, the "metd" directory
    > disappears! It's deleted![/color]

    If I create the "metd" dir by hand before calling the plugin
    from the GUI everything works! This is really puzzling:

    If the "metd" doesn't exist the Python script _appears_
    to create it, but somehow tempfile.mkstem p can't put the
    tempfile inside. If, on the other hand, I create that
    directory beforehand there's no problem. What's
    going on? Is

    os.path.isdir('/tmp/991319584/metd/')

    lying to me when it says "True"? Is the "metd" actually
    there but in some weird state which messes up tempfile.mkstem p?

    I guess I could try making the temp dir from within
    the plugin instead (and then calling the script afterwards).
    This is all very strange, though...

    Anyway, sorry again for all the posts, it's really late! :/

    Cheers,

    --
    marco@reimeika. ca
    Gunnm: Broken Angel http://amv.reimeika.ca
    http://reimeika.ca/ http://photo.reimeika.ca

    Comment

    • marco

      #3
      Re: tempfile.mkstem p problem?


      Sorry for yet another followup.
      [color=blue]
      > the plugin/script is being called from yet another
      > Perl script. I guess I should look more closely
      > at how this is taking place. In the meantime, any ideas
      > would be appreciated![/color]

      The Perl script runs:

      system("$plugin encode $fields");

      When I do:

      plugin encode fields

      on the command line things work fine. Any ideas?

      Cheers!

      --
      marco@reimeika. ca
      Gunnm: Broken Angel http://amv.reimeika.ca
      http://reimeika.ca/ http://photo.reimeika.ca

      Comment

      Working...