Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert " Use Threading.current_thread" #37

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion fasteners/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,29 @@ class ReaderWriterLock(object):
#: Reader owner type/string constant.
READER = 'r'

@staticmethod
def _fetch_current_thread_functor():
# Until https://github.com/eventlet/eventlet/issues/172 is resolved
# or addressed we have to use complicated workaround to get a object
# that will not be recycled; the usage of threading.current_thread()
# doesn't appear to currently be monkey patched and therefore isn't
# reliable to use (and breaks badly when used as all threads share
# the same current_thread() object)...
if eventlet is not None and eventlet_patcher is not None:
if eventlet_patcher.is_monkey_patched('thread'):
return eventlet.getcurrent
return threading.current_thread

def __init__(self,
condition_cls=threading.Condition,
current_thread_functor=None):
self._writer = None
self._pending_writers = collections.deque()
self._readers = {}
self._cond = condition_cls()
self._current_thread = threading.current_thread
if current_thread_functor is None:
current_thread_functor = self._fetch_current_thread_functor()
self._current_thread = current_thread_functor

@property
def has_pending_writers(self):
Expand Down