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

Allow the pool lock to be specialized #41

Merged
merged 4 commits into from May 11, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions pymemcache/client.py
Expand Up @@ -836,7 +836,10 @@ def __init__(self,
ignore_exc=False,
socket_module=socket,
key_prefix=b'',
max_pool_size=None):
max_pool_size=None,
# Allow this to be a different style of lock (eventlet
# lock/semaphore for example, that works with greenthreads).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type of documentation generally goes in a docblock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya. I'll add those into a docstring/block on the class.

lock_generator=None):
self.server = server
self.serializer = serializer
self.deserializer = deserializer
Expand All @@ -853,7 +856,8 @@ def __init__(self,
self.client_pool = pool.ObjectPool(
self._create_client,
after_remove=lambda client: client.close(),
max_size=max_pool_size)
max_size=max_pool_size,
lock_generator=lock_generator)

def check_key(self, key):
"""Checks key and add key_prefix."""
Expand Down
8 changes: 6 additions & 2 deletions pymemcache/pool.py
Expand Up @@ -24,11 +24,15 @@ class ObjectPool(object):
"""A pool of objects that release/creates/destroys as needed."""

def __init__(self, obj_creator,
after_remove=None, max_size=None):
after_remove=None, max_size=None,
lock_generator=None):
self._used_objs = collections.deque()
self._free_objs = collections.deque()
self._obj_creator = obj_creator
self._lock = threading.Lock()
if lock_generator is None:
self._lock = threading.Lock()
else:
self._lock = lock_generator()
self._after_remove = after_remove
max_size = max_size or 2 ** 31
if not isinstance(max_size, six.integer_types) or max_size < 0:
Expand Down