馬老師MySQL+JDBC
import threadingimport multiprocessingdef sum_n(n, e=None):
? ?s= 0
? ?for i in range(1, n+1):
? ? ? ?if e and i % e == 0:
? ? ? ? ? ?continue
? ? ? ?s += i
? ?name = threading.current_thread().name ?# 當(dāng)前線程的名稱
? ?pname = multiprocessing.current_process().name ? ?print(pname, name, n, '以內(nèi)的所有數(shù)據(jù)和為', s)def t():
? ?# 快捷鍵: ctrl+p 顯示方法的參數(shù)
? ?# 創(chuàng)建三個進程(子進程), 當(dāng)前所在的進程是父進程
? ?thread1 = threading.Thread(target=sum_n, args=(100,))
? ?thread2 = threading.Thread(target=sum_n, args=(1000, 5)) ?# ctrl+d 快速復(fù)制一行
? ?thread3 = threading.Thread(target=sum_n, kwargs=dict(n=10000, e=2))
標(biāo)簽: