最近經過關鍵詞匹配的方式查找數據中的可用樣本,因爲速度比較慢,因此想把多線程用上去,提升一下速度。如今熟悉一下基本的操做:python
""" Function: 多線程操做樣例 Author: dyx DateTime: 20191021 """ from threading import Thread import time def main(name="python"): for i in range(5): print('hi', name) time.sleep(1) # 建立線程1 不指定參數 thread_01 = Thread(target=main) # 啓動線程1 thread_01.start() thread_02 = Thread(target=main, args=("deng",)) thread_02.start() if __name__ == '__main__': t1 = time.time() main() t2 = time.time() print('單機耗時:{}'.format(t2-t1))