diff --git a/memcache.py b/memcache.py index 05b6657..05a0df4 100644 --- a/memcache.py +++ b/memcache.py @@ -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. @@ -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 @@ -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') @@ -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 diff --git a/setup.py b/setup.py index 93cbe4d..990551f 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ maintainer="Sean Reifschneider", maintainer_email="jafo@tummy.com", 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=[