def getInit(class_name):
"""动态加载模块"""
resultmodule = __import__(class_name, globals(), locals(), [class_name])
resultclass = getattr(resultmodule, class_name)
return resultclass()
import threading, time
class b:
def __init__(self, *args, **kwargs):
self.name = "b"
self.class_name = "a"
print "%s is inited" % (self.name)
def __del__(self):
print "%s is deleted" % (self.name)
def other_run(self, obj=None):
if obj:
obj.run()
def run(self, *args, **kwargs):
obj = getInit(self.class_name)
obj.run()
self.other_run(obj)
print "%s is run" % (self.name)
def treading():
n = 0
c = b()
while n<2:
n += 1
print "\n"