Is tempfile.mkdtemp() thread-safe?

Discussion in 'Python' started by Gabriel Rossetti, Aug 21, 2008.

  1. 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
     
    Gabriel Rossetti, Aug 21, 2008
    #1
    1. Advertising

  2. 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
     
    Gabriel Rossetti, Aug 22, 2008
    #2
    1. Advertising

  3. 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
     
    Gabriel Rossetti, Aug 22, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabriel Rossetti
    Replies:
    0
    Views:
    1,329
    Gabriel Rossetti
    Aug 29, 2008
  2. Replies:
    1
    Views:
    343
    Brian Candler
    Aug 12, 2003
  3. Aredridel

    Not just $SAFE, but damn $SAFE

    Aredridel, Sep 2, 2004, in forum: Ruby
    Replies:
    19
    Views:
    244
  4. John Nagle
    Replies:
    5
    Views:
    475
    John Nagle
    Mar 12, 2012
  5. Alex van der Spek

    Difference between tempfile and spooled tempfile?

    Alex van der Spek, Apr 5, 2012, in forum: Python
    Replies:
    2
    Views:
    361
    Steve Howell
    Apr 5, 2012
Loading...

Share This Page