From c1c018f3a2c3aea01dbc9651a282957fd2007872 Mon Sep 17 00:00:00 2001 From: Chow Loong Jin Date: Thu, 25 Oct 2018 15:39:05 +0800 Subject: [PATCH] Expose a non-thread-local base client class This allows more advanced client pooling mechanisms to be used. --- memcache.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/memcache.py b/memcache.py index 05b6657..85273a5 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 @@ -1500,6 +1502,14 @@ 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