From b12e2d1c8c1ce2c7fac28fe7a7fb73ef9882d970 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 18 Sep 2010 10:53:50 -0400 Subject: [PATCH] fixed race condition in creating directories --- quadtree.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/quadtree.py b/quadtree.py index 7ff4f1c..c666a93 100644 --- a/quadtree.py +++ b/quadtree.py @@ -432,7 +432,15 @@ def render_worldtile(chunks, colstart, colend, rowstart, rowend, path): # Create the directory if not exists dirdest = os.path.dirname(path) if not os.path.exists(dirdest): - os.makedirs(dirdest) + try: + os.makedirs(dirdest) + except OSError, e: + # Ignore errno EEXIST: file exists. Since this is multithreaded, + # two processes could conceivably try and create the same directory + # at the same time. + import errno + if e.errno != errno.EEXIST: + raise imghash = hashlib.md5() for col, row, chunkfile in chunks: