SIngleton from __defaults__
Asaf Las
roegltd at gmail.com
Wed Jan 22 17:34:12 EST 2014
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote:
> On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las <r... at gmail.com> wrote:
> ChrisA
and this one is about multiclass container function with
multithreading support:
import threading
def provider(cls, x = [threading.Lock(), {}]):
provider.__defaults__[0][0].acquire()
if not cls.__name__ in provider.__defaults__[0][1]:
provider.__defaults__[0][1][cls.__name__] = cls()
provider.__defaults__[0][0].release()
return provider.__defaults__[0][1][cls.__name__]
class whatever():
def __init__(self):
self.one = 1
self.zero = 0
class whatever1():
def __init__(self):
self.one = 1
self.zero = 0
print(id(provider(whatever)))
print(id(provider(whatever)))
print(id(provider(whatever1)))
print(id(provider(whatever1)))
could be there some hidden faults i missed?
/Asaf
More information about the Python-list
mailing list