Commits

Mike Bayer committed 7c34b2b

- keep fcntl import local to FileLock to allow import on windows - #44

Comments (0)

Files changed (1)

dogpile/cache/backends/file.py

 from dogpile.cache import compat
 from dogpile.cache import util
 import os
-import fcntl
 
 __all__ = 'DBMBackend', 'FileLock', 'AbstractFileLock'
 
         self._filedescriptor = compat.threading.local()
         self.filename = filename
 
+    @util.memoized_property
+    def _module(self):
+        import fcntl
+        return fcntl
+
     @property
     def is_open(self):
         return hasattr(self._filedescriptor, 'fileno')
 
     def acquire_read_lock(self, wait):
-        return self._acquire(wait, os.O_RDONLY, fcntl.LOCK_SH)
+        return self._acquire(wait, os.O_RDONLY, self._module.LOCK_SH)
 
     def acquire_write_lock(self, wait):
-        return self._acquire(wait, os.O_WRONLY, fcntl.LOCK_EX)
+        return self._acquire(wait, os.O_WRONLY, self._module.LOCK_EX)
 
     def release_read_lock(self):
         self._release()
         fileno = os.open(self.filename, wrflag)
         try:
             if not wait:
-                lockflag |= fcntl.LOCK_NB
-            fcntl.flock(fileno, lockflag)
+                lockflag |= self._module.LOCK_NB
+            self._module.flock(fileno, lockflag)
         except IOError:
             os.close(fileno)
             if not wait:
         except AttributeError:
             return
         else:
-            fcntl.flock(fileno, fcntl.LOCK_UN)
+            self._module.flock(fileno, self._module.LOCK_UN)
             os.close(fileno)
             del self._filedescriptor.fileno
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.