1.线程的创建方式
"""
import win32api
import threading
def show(i):
win32api.MessageBox(0,"你的账户很危险"+str(i),"来自支付宝的问候",6)
#target=show 线程函数,args=()参数 类的构造实现多线程,不考虑通信冲突
threading.Thread(target=show,args=(1,)).start()
threading.Thread(target=show,args=(1,)).start()#target关键字参数传递函数名,args关键字参数参数传递函数的参数
threading.Thread(target=show,args=(1,)).start()
threading.Thread(target=show,args=(1,)).start()
"""
"""
import win32api#引用系统函数,不考虑冲突,通信
import _thread #多线程
def show(i):
win32api.MessageBox(0,"你的账户很危险","来自支付宝的问候"+str(i))
for i in range(5):#创建五个线程
_thread.start_new_thread(show,(i,))#(i)元组,用于传递参数,函数实现多线程
show(99)#主线程
"""
import threading
import time
import win32api
class Mythread(threading.Thread):
def __init__(self,num):
threading.Thread.__init__(self)
self.num=num
def run(self):
win32api.MessageBox(0,"你的账户有危险","来自支付宝的问候",16)
for i in range(5):
t=Mythread(i)
t.start()
t.join()
D:\PycharmProjects\untitled11\venv\Scripts\python.exe D:/PycharmProjects/untitled11/多线程/线程中阶/1.创建多线程的方式.py
Process finished with exit code 0