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

Expose a non-thread-local base client class #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ class _ConnectionDeadError(Exception):
_SOCKET_TIMEOUT = 3 # number of seconds before sockets timeout.


class Client(threading.local):
"""Object representing a pool of memcache servers.
class BasicClient(object):
"""Object representing a pool of memcache servers. This is not thread-safe,
and should either be wrapped in a thread-local variable or other
synchronizing mechanism.

See L{memcache} for an overview.

Expand Down Expand Up @@ -207,7 +209,7 @@ def __init__(self, servers, debug=0, pickleProtocol=0,
to ensure it is the correct length and composed of the right
characters.
"""
super(Client, self).__init__()
super(BasicClient, self).__init__()
self.debug = debug
self.dead_retry = dead_retry
self.socket_timeout = socket_timeout
Expand Down Expand Up @@ -1440,7 +1442,8 @@ def readline(self, raise_exception=False):
if self.socket:
recv = self.socket.recv
else:
recv = lambda bufsize: b''
def recv(bufsize):
return b''

while True:
index = buf.find(b'\r\n')
Expand Down Expand Up @@ -1500,6 +1503,13 @@ def __str__(self):
return "unix:%s%s" % (self.address, d)


class Client(threading.local, BasicClient):
"""Thread-safe memcache client. See L{BasicClient} for more information on
how to use this class.
"""
pass


def _doctest():
import doctest
import memcache
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
maintainer="Sean Reifschneider",
maintainer_email="[email protected]",
url="https://github.com/linsomniac/python-memcached",
download_url="https://github.com/linsomniac/python-memcached/releases/download/{0}/python-memcached-{0}.tar.gz".format(version),
download_url="https://github.com/linsomniac/python-memcached/releases/download/{0}/python-memcached-{0}.tar.gz".format(version), # noqa
py_modules=["memcache"],
install_requires=open('requirements.txt').read().split(),
classifiers=[
Expand Down