Skip to content

Commit

Permalink
Expose a non-thread-local base client class
Browse files Browse the repository at this point in the history
This allows more advanced client pooling mechanisms to be used.
  • Loading branch information
hyperair committed Oct 25, 2018
1 parent bad4122 commit c1c018f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 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 @@ -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
Expand Down

0 comments on commit c1c018f

Please sign in to comment.