#测试单元
#Anaconda指的是一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项 import unittest #测试单元class TestAddition(unittest.TestCase): def setUp(self): #开始 print('Setting up the test') print(1) def tearDown(self): #结束 print(2) print('Tearing down the test') def test_twoPlusTwo(self): total = 2+2 self.assertEqual(4, total); #断言if __name__ == '__main__': unittest.main(argv=[''], exit=False) %reset #清除内存 如声明变量等之类的
# 一个线程
import threadingimport timeclass Crawler(threading.Thread): #类 def __init__(self): #初始化 threading.Thread.__init__(self) self.done = False def isDone(self): return self.done def run(self): print(66) time.sleep(5) self.done = True print('here') raise Exception('Something bad happened!')t = Crawler() #实例化t.start() #线程开始while True: time.sleep(1) print(55) if t.isDone(): #True时候 print('Done') break if not t.isAlive(): #线程崩溃 就重启线程 t = Crawler() t.start()