os.ChDir() not thread-safe; was : Is tempfile.mkdtemp() thread-safe?

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

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

    Is tempfile.mkdtemp() thread-safe?

    Gabriel Rossetti, Aug 21, 2008, in forum: Python
    Replies:
    2
    Views:
    537
    Gabriel Rossetti
    Aug 22, 2008
  2. vulpes
    Replies:
    3
    Views:
    127
    vulpes
    Mar 21, 2007
  3. Mr_Tibs

    FileUtils.chdir thread safety

    Mr_Tibs, Sep 8, 2008, in forum: Ruby
    Replies:
    19
    Views:
    338
    Charles Oliver Nutter
    Sep 11, 2008
  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