Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is tempfile.mkdtemp() thread-safe?

Reply
Thread Tools

Is tempfile.mkdtemp() thread-safe?

 
 
Gabriel Rossetti
Guest
Posts: n/a
 
      08-21-2008
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
 
Reply With Quote
 
 
 
 
Gabriel Rossetti
Guest
Posts: n/a
 
      08-22-2008
Dennis Lee Bieber wrote:
> On Thu, 21 Aug 2008 13:22:33 +0200, Gabriel Rossetti
> <> declaimed 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
 
Reply With Quote
 
 
 
 
Gabriel Rossetti
Guest
Posts: n/a
 
      08-22-2008
Dennis Lee Bieber wrote:
> On Thu, 21 Aug 2008 13:22:33 +0200, Gabriel Rossetti
> <> declaimed 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57