The Voidspace Techie Blog

Gravatar I've done something similar in WebStack, although I imagine that my scheme could be substantially improved. See here:

http://www.boddie.org.uk/python/ ...repository.html


Gravatar Pardon my ignorance, but why create a directory rather than just a file with a distinctive name?


Gravatar The equivalent code creating a named file would look like :

if not os.path.isfile(filename):
h = open(filename, 'w')
h.write('')
h.close()

You've got a "race condition" between the first two line - if two processes attempt this at the same time.

os.mkdir(filename) is more "atomic" - if two processes attempt it at the same time it is up to the operating system to return an error to one of them.

That is my understanding anyway.


Name:

Email:

URL:

Comment:  ? 

 

Commenting by HaloScan