Permalink
Browse files

Use tempfile.mkdtemp to create temp dir

Using tempfile.mkdtemp is the standard way to safely create a temporary
directory and allows multiple Loader instances to be ran in parallel
avoiding more that one instance trying to create a time stamped
directory.
  • Loading branch information...
walkermatt committed May 19, 2014
1 parent f0363fd commit 199e66f7064e341b1365eb10a3d5a572b45b7fdb
Showing with 2 additions and 4 deletions.
  1. +2 −4 python/loader.py
View
6 python/loader.py 100755 → 100644
@@ -28,10 +28,10 @@
import sys
import os
import shutil
-import datetime
import shlex
import subprocess
from string import Template
+import tempfile
class LoaderError(Exception):
@@ -108,10 +108,8 @@ def setup(self):
# Create a temp directory as a child to the temp
# directory specified to hold all of our working
# files and to make cleaning up simple
- timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
- self.tmp_dir = os.path.join(self.tmp_dir, 'loader_' + timestamp)
try:
- os.mkdir(self.tmp_dir)
+ self.tmp_dir = tempfile.mkdtemp(dir=self.tmp_dir)
except (OSError) as ex:
raise CreateTempDirError(ex.errno, ex.strerror, self.tmp_dir)

0 comments on commit 199e66f

Please sign in to comment.