首页 > 代码库 > python之多线程举例

python之多线程举例

 

 1 # 多线程举例
 2 from threading import Thread
 3 from threading import current_thread
 4 
 5 
 6 class messager(Thread):
 7     def run(self):
 8         for x in range(20):
 9             print(current_thread().getName())
10 
11     def print_num(self, n):
12         for x in range(20):
13             print(n)
14 
15 
16 x_msg_obj = messager(name="发送消息")
17 y_msg_obj = messager(name="接收消息")
18 
19 x_msg_obj.start()
20 y_msg_obj.start()

 

python之多线程举例