-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNote_singleton.py
57 lines (38 loc) · 907 Bytes
/
Note_singleton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# encoding: utf-8
# product.py
# product
# Created by txooo on 2018/11/19
# Copyright © 2018 txooo. All rights reserved.
import datetime
import time
def singleton(cls):
instance = cls()
instance.__call__ = lambda: instance
return instance
@singleton
class Highlander(object):
# x = 100
# Of course you can have any attributes or methods you like.
def __init__(self):
print('创建')
self.config_params()
def config_params(self):
self.x = 100
self.date = datetime.datetime.now()
def __call__(self, *args, **kwargs):
print('调用')
def get_value(self, input):
return 200 + input
def __del__(self):
print('__del__')
self.x = None
self.date = None
print(Highlander.date, Highlander)
print('休眠')
time.sleep(3)
print(Highlander.date)
print('休眠结束')
print('删除')
Highlander.config_params()
print(Highlander.date)