Commit 47a1fee6 by rfkelly0

Use custom DummyLock class rather than dummy_threading.RLock

dummy_threading is not safe to use in the presence of actual threads.
parent 1dfc4c0a
...@@ -15,7 +15,7 @@ implementations of this interface such as: ...@@ -15,7 +15,7 @@ implementations of this interface such as:
""" """
__version__ = "0.2.0a3" __version__ = "0.2.0a4"
__author__ = "Will McGugan (will@willmcgugan.com)" __author__ = "Will McGugan (will@willmcgugan.com)"
# 'base' imports * from 'path' and 'errors', so their # 'base' imports * from 'path' and 'errors', so their
......
...@@ -18,12 +18,30 @@ try: ...@@ -18,12 +18,30 @@ try:
import threading import threading
except ImportError: except ImportError:
import dummy_threading as threading import dummy_threading as threading
import dummy_threading
from fs.path import * from fs.path import *
from fs.errors import * from fs.errors import *
class DummyLock:
"""A dummy lock object that doesn't do anything.
This is used as a placeholder when locking is disabled. We can't
directly use the Lock class from the dummy_threading module, since
it attempts to sanity-check the sequence of acquire/release calls
in a way that breaks when real threading is available.
"""
def acquire(self,blocking=1):
"""Acquiring a DummyLock always succeeds."""
return 1
def release(self):
"""Releasing a DummyLock always succeeds."""
pass
def silence_fserrors(f, *args, **kwargs): def silence_fserrors(f, *args, **kwargs):
"""Perform a function call and return None if FSError is thrown """Perform a function call and return None if FSError is thrown
...@@ -139,7 +157,7 @@ class FS(object): ...@@ -139,7 +157,7 @@ class FS(object):
if thread_synchronize: if thread_synchronize:
self._lock = threading.RLock() self._lock = threading.RLock()
else: else:
self._lock = dummy_threading.RLock() self._lock = DummyLock()
def __getstate__(self): def __getstate__(self):
...@@ -163,7 +181,7 @@ class FS(object): ...@@ -163,7 +181,7 @@ class FS(object):
if lock: if lock:
self._lock = threading.RLock() self._lock = threading.RLock()
else: else:
self._lock = dummy_threading.RLock() self._lock = DummyLock()
def getsyspath(self, path, allow_none=False): def getsyspath(self, path, allow_none=False):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment