Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SedlacekStorage(object):
- """
- Please note, that every SedlacekStorage subclass is a singleton. You can't
- use sync & async versions of +SedlacekStorage in the same process.
- """
- _tornado_client = None
- _asyncio_client = None
- def __new__(cls, *args, **kwargs):
- if not cls._instance:
- # protect parent from our specific args
- kwargscopy = dict(kwargs)
- for key in ['async', 'timeout']:
- if key in kwargscopy:
- del kwargscopy[key]
- cls._instance = super(SedlacekStorage, cls) \
- .__new__(cls, *args, **kwargscopy)
- return cls._instance
- class A(SedlacekStorage):
- _instance = None
- class B(A):
- pass
- a1 = A()
- print(A._instance, B._instance)
- b1 = B()
- b2 = B()
- print(b1 is b2)
- print(a1 is b2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement