os.ChDir() not thread-safe; was : Is tempfile.mkdtemp() thread-safe?
Gabriel Rossetti
gabriel.rossetti at arimaz.com
Fri Aug 29 04:30:00 EDT 2008
Gabriel Rossetti wrote:
> 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
I think I found what was wrong, I was using os.chDir(), and the current
directory is shared by all threads :
http://www.biais.org/blog/index.php/2007/01/23/19-python-threads-and-oschdir
http://bugs.python.org/issue1367
I hope this helps anyone that ever has such a problem!
Gabriel
More information about the Python-list
mailing list