473,782 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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(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!


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,

--
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3831
by: Pierre Rouleau | last post by:
Hi all! I am using Python 2.3.1 on Win32 (NT, 2000). Whenever a file imports the standard tempfile module, Python 2.3.1 issues the following warning: C:\Python23\lib\fcntl.py:7: DeprecationWarning: the FCNTL module is Deprecated; please use fcntl DeprecationWarning).
3
2858
by: Thomas Guettler | last post by:
Hi! Is there a need for the "@" in the filenames created with tempfile.mktemp()? I think it would be better to use only characters which are "shell save". At least with bash you need to quote the "@". Copy&past of the filename does not work.
0
1119
by: marco | last post by:
Boy, do I feel dumb. And yet... Well, the problem was that the permissions of the directory were "drw-------" when it was called from the Perl script. I dunno, I'm too tired to figure out why, some umask thing. Doing: os.chmod(work_dir, 0755) fixes everything...
5
1718
by: Gregory Piñero | last post by:
Hey group, I have a command line tool that I want to be able to call from a Python script. The problem is that this tool only writes to a file. So my solution is to give the tool a temporary file to write to and then have Python read that file. I figure that's the safest way to deal with this sort of thing. (But I'm open to better methods). Here's my code so far, could anyone tell me the proper way to use
0
1205
by: Colin Wildsmith | last post by:
Hello, I am trying to create a temp file, however the file that is created is still there after the program has completed. Why is this so? CoLe #!/usr/bin/python import os, tempfile, sys
6
1391
by: James T. Dennis | last post by:
Tonight I discovered something odd in the __doc__ for tempfile as shipped with Python 2.4.4 and 2.5: it says: This module also provides some data items to the user: TMP_MAX - maximum number of names that will be tried before giving up. template - the default prefix for all temporary names. You may change this to control the default prefix.
4
1136
by: billiejoex | last post by:
Hi all, I would like to use tempfile module to generate files having unique names excepting that I don't want them to be removed after closing. Does it is possible?
9
3755
by: billiejoex | last post by:
Hi there. I'm trying to generate a brand new file with a unique name by using tempfile.mkstemp(). In conjunction I used os.fdopen() to get a wrapper around file properties (write & read methods, and so on...) but 'name' attribute does not contain the correct file name. Why? <fdopen> Moreover, I'd like to know if I'm doing fine. Does this approach avoid
7
578
by: byte8bits | last post by:
Wondering if someone would help me to better understand tempfile. I attempt to create a tempfile, write to it, read it, but it is not behaving as I expect. Any tips? <open file '<fdopen>', mode 'w+b' at 0xab364968> 0 0 0
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9942
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8967
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.