Is tempfile.mkdtemp() thread-safe?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Rossetti

    Is tempfile.mkdtemp() thread-safe?

    Hello,

    I'm using tempfile.mkdtem p() 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.mkdtem p()) doesn't exist.
    I suspect that tempfile.mkdtem p() 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

    #2
    Re: Is tempfile.mkdtem p() thread-safe?

    Dennis Lee Bieber wrote:
    On Thu, 21 Aug 2008 13:22:33 +0200, Gabriel Rossetti
    <gabriel.rosset ti@arimaz.comde claimed the following in
    comp.lang.pytho n:
    >
    >
    >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

    Comment

    • Gabriel Rossetti

      #3
      Re: Is tempfile.mkdtem p() thread-safe?

      Dennis Lee Bieber wrote:
      On Thu, 21 Aug 2008 13:22:33 +0200, Gabriel Rossetti
      <gabriel.rosset ti@arimaz.comde claimed the following in
      comp.lang.pytho n:
      >
      >
      >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

      Comment

      Working...