source: OpenRLabs-Git/web2py/applications/rlabs/modules/dummy.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100644
File size: 1.2 KB
Line 
1
2import time
3from random import randint
4import threading
5
6class Singleton(type):
7    instance = None
8    def __call__(cls, *args, **kw):
9        if not cls.instance:
10             cls.instance = super(Singleton, cls).__call__(*args, **kw)
11        return cls.instance
12
13
14class DummySingleton(metaclass=Singleton):
15   
16    def __init__(self):
17        self.var = None
18        self.local = threading.local()
19        print(self)
20       
21    def set_var(self, var):
22        self.local.var = var
23        self.var = var
24               
25        #print('my var' + str(self.local.var))
26        time.sleep(randint(10,20))
27        print('Singleton var pasada ' + str(var) + \
28              ' local var ' + str(self.local.var) + \
29              ' non local ' + str(self.var))
30         
31class Dummy:
32   
33    def __init__(self):
34        self.var = None
35        self.local = threading.local()
36        print(self)
37       
38    def set_var(self, var):
39        self.local.var = var
40        self.var = var
41               
42        #print('my var' + str(self.local.var))
43        time.sleep(randint(10,20))
44        print('var pasada ' + str(var) + \
45              ' local var ' + str(self.local.var) + \
46              ' non local ' + str(self.var))
Note: See TracBrowser for help on using the repository browser.