

from tornado.options import define, options
import tornadoasyncmemcache

define("db_addr_list", type=list, default=['192.168.0.176:19803'])

class MemcachedClient(object):
    @staticmethod
    def instance():
        if not hasattr(MemcachedClient, "_instance"):
            MemcachedClient._instance = \
                tornadoasyncmemcache.ClientPool(options.db_addr_list, 
                                                maxclients=100)
        return MemcachedClient._instance

def get(key, callback):
    MemcachedClient.instance().get(key, callback=callback)



from tornado.options import define, options
import tornadoasyncmemcache

define("db_addr_list", type=list, default=['192.168.0.176:19803'])

class MemcachedClient(object):
    def __new__(cls):
        if not hasattr(cls, '_instance'):
            cls._instance = \
                tornadoasyncmemcache.ClientPool(options.db_addr_list,
                                                maxclients=100)
        return cls._instance
def get_memcached(key, callback):
    MemcachedClient.instance().get(key, callback=callback)

Modify db client to __new__
Modify db client to __new__

change db singlton from instance() staticmethod to __new__()

  
  
  from tornado.options import define, options
  import tornadoasyncmemcache
  
  define("db_addr_list", type=list, default=['192.168.0.176:19803'])
  
  class MemcachedClient(object):
+     def __new__(cls):
-     @staticmethod
-     def instance():
-         if not hasattr(MemcachedClient, "_instance"):
+         if not hasattr(cls, '_instance'):
-             MemcachedClient._instance = \
+             cls._instance = \
-                 tornadoasyncmemcache.ClientPool(options.db_addr_list, 
+                 tornadoasyncmemcache.ClientPool(options.db_addr_list,
                                                  maxclients=100)
-         return MemcachedClient._instance
+         return cls._instance
- 
- def get(key, callback):
+ def get_memcached(key, callback):
      MemcachedClient.instance().get(key, callback=callback)
  
Modify db client to __new__
## Code Before:


from tornado.options import define, options
import tornadoasyncmemcache

define("db_addr_list", type=list, default=['192.168.0.176:19803'])

class MemcachedClient(object):
    @staticmethod
    def instance():
        if not hasattr(MemcachedClient, "_instance"):
            MemcachedClient._instance = \
                tornadoasyncmemcache.ClientPool(options.db_addr_list, 
                                                maxclients=100)
        return MemcachedClient._instance

def get(key, callback):
    MemcachedClient.instance().get(key, callback=callback)

## Instruction:
Modify db client to __new__
## Code After:


from tornado.options import define, options
import tornadoasyncmemcache

define("db_addr_list", type=list, default=['192.168.0.176:19803'])

class MemcachedClient(object):
    def __new__(cls):
        if not hasattr(cls, '_instance'):
            cls._instance = \
                tornadoasyncmemcache.ClientPool(options.db_addr_list,
                                                maxclients=100)
        return cls._instance
def get_memcached(key, callback):
    MemcachedClient.instance().get(key, callback=callback)
