473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is tempfile.mkdtemp() thread-safe?

Hello,

I'm using tempfile.mkdtemp() in a multithreading program and I've been
having problems with it. Sometimes it tells me the file I'm trying to
access (in the directory created with tempfile.mkdtemp()) doesn't exist.
I suspect that tempfile.mkdtemp() returns the same directory to
different threads sometimes. Does anyone know anything about this or
have a solution? I have to create unique and temp. directories to use an
external program that creates a temp. file with the same name every
time, thus if I want to call it from several threads, each call has to
be from a different directory.

Thank you,
Gabriel
Aug 21 '08 #1
2 3949
Dennis Lee Bieber wrote:
On Thu, 21 Aug 2008 13:22:33 +0200, Gabriel Rossetti
<ga**************@arimaz.comdeclaimed the following in
comp.lang.python:

>have a solution? I have to create unique and temp. directories to use an
external program that creates a temp. file with the same name every
time, thus if I want to call it from several threads, each call has to
be from a different directory.

Have you considered passing in the ID (string-formatted) of the
thread itself as a parameter (suffix)?
No, that's a very good idea... you mean with the id() builtin function
correct? I'll try that, then. But if it's really not thread-safe, then
it will still return the same tmp dir to both calls.
No, that's a very good idea... you mean with the id() builtin function
correct? I'll try that, thanl
Aug 22 '08 #2
Dennis Lee Bieber wrote:
On Thu, 21 Aug 2008 13:22:33 +0200, Gabriel Rossetti
<ga**************@arimaz.comdeclaimed the following in
comp.lang.python:

>have a solution? I have to create unique and temp. directories to use an
external program that creates a temp. file with the same name every
time, thus if I want to call it from several threads, each call has to
be from a different directory.

Have you considered passing in the ID (string-formatted) of the
thread itself as a parameter (suffix)?
Ok, it doesn't work, I think it's not thread-safe, but if someone knows
better, I'd appreciate it.

Thanks,
Gabriel
Aug 22 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
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:...
3
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...
2
by: marco | last post by:
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 --...
1
by: Matt Garman | last post by:
I've been working on a curses-based application in Python. My application effectively has a series of screens (or windows). When one screen closes, the previous screen should be exactly redrawin...
3
by: Diffident | last post by:
Hello All, Following is a static method. Can you please tell me if this is threadsafe...why? If it is not threadsafe...why? Thank you. public static string...
6
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...
9
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,...
7
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...
0
by: Gabriel Rossetti | last post by:
Gabriel Rossetti wrote: I think I found what was wrong, I was using os.chDir(), and the current directory is shared by all threads : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...

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.