469,593 Members | 1,877 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,593 developers. It's quick & easy.

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.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
--
ma***@reimeika.ca
Gunnm: Broken Angel http://amv.reimeika.ca
http://reimeika.ca/ http://photo.reimeika.ca
Jul 18 '05 #1
2 3834

The last one! For real!

marco <ma***@reimeika.ca> writes:
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,

--
ma***@reimeika.ca
Gunnm: Broken Angel http://amv.reimeika.ca
http://reimeika.ca/ http://photo.reimeika.ca
Jul 18 '05 #2

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!

--
ma***@reimeika.ca
Gunnm: Broken Angel http://amv.reimeika.ca
http://reimeika.ca/ http://photo.reimeika.ca
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Thomas Guettler | last post: by
reply views Thread by marco | last post: by
5 posts views Thread by Gregory Piñero | last post: by
reply views Thread by Colin Wildsmith | last post: by
6 posts views Thread by James T. Dennis | last post: by
4 posts views Thread by billiejoex | last post: by
9 posts views Thread by billiejoex | last post: by
7 posts views Thread by byte8bits | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.