Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of </p> <pre><code>if not os.path.exists(self.cache_location): os.mkdir(self.cache_location) </code></pre> <p>you could do</p> <pre><code>try: os.makedirs(self.cache_location) except OSError: pass </code></pre> <p>As you would end up with the same <em>functionality</em>.</p> <p><sub>DISCLAIMER: I don't know how Pythonic this might be.</sub></p> <hr> <p>Using <code>SQLite3</code>, <em>might</em> be a bit of overkill, but would add a <em>lot</em> of functionality and flexibility to your use case.</p> <p>If you have to do a lot of "selecting", concurrent inserting and filtering, it's a great idea to use <code>SQLite3</code>, as it wont add too much complexity over simple files (it could be argued that it removes complexity).</p> <hr> <p>Rereading your question (and comments) I can better understand your problem.</p> <p>What is the possibility that a <strong>file</strong> could create the same race condition?</p> <p>If it is small enough, then I'd do something like:</p> <pre><code>if not os.path.isfile(self.cache_location): try: os.makedirs(self.cache_location) except OSError: pass </code></pre> <p>Also, reading your code, I'd change </p> <pre><code>else: # Our target dir is already a file, or different error, # relay the error! raise OSError(e) </code></pre> <p>to</p> <pre><code>else: # Our target dir is already a file, or different error, # relay the error! raise </code></pre> <p>as it's really what you want, Python to reraise the exact same exception <sub>(just nitpicking)</sub>.</p> <hr> <p>One more thing, may be <a href="https://stackoverflow.com/questions/1474052/synchronize-shell-script-execution" title="Synchronize shell script execution">this</a> could be of use for you (Unix-like only).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload