tempfile.mkstemp problem?

M

marco

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.mkstemp('.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(work_dir):
if not quiet: print 'Creating ' + work_dir
try:
os.makedirs(work_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.mkstemp('.mpv', '', work_dir)[1]

The "os.path.isdir" says "True". Here's the kicker:
after the tempfile.mkstemp 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
 
M

marco

Sorry for yet another followup.
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!

The Perl script runs:

system("$plugin encode $fields");

When I do:

plugin encode fields

on the command line things work fine. Any ideas?

Cheers!
 
M

marco

The last one! For real!

marco said:
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(work_dir):
if not quiet: print 'Creating ' + work_dir
try:
os.makedirs(work_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.mkstemp('.mpv', '', work_dir)[1]

The "os.path.isdir" says "True". Here's the kicker:
after the tempfile.mkstemp error, the "metd" directory
disappears! It's deleted!

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.mkstemp 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.mkstemp?

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top