python note 29 线程创建

1、线程

  

import time
import threading

def task(a1,a2,a3):
    time.sleep(2)
    print('拿快递')

def play():
    print('和女朋友去耍')


def wm():
    print('去拿外卖')


# 创建一个线程
# 让该线程去执行任务:函数
t1 = threading.Thread(target=task,args=(1,2,3,))
# 去执行吧
t1.start()


# 创建一个线程
# 让该线程去执行任务:函数
t2 = threading.Thread(target=play)
# 去执行吧
t2.start()


# 创建一个线程
# 让该线程去执行任务:函数
t3 = threading.Thread(target=wm)
# 去执行吧
t3.start()

2、socketserver

import socketserver

class MyServer(socketserver.BaseRequestHandler):
    def handle(self):
        self.request
        self.client_address
        self.server
        # 编写代码

server = socketserver.ThreadingTCPServer(('192.168.13.84',8001,),MyServer)
"""
server.server_address = server_address
server.RequestHandlerClass = RequestHandlerClass
server.__is_shut_down = threading.Event()
server.__shutdown_request = False
server.socket = socket....
    - socket.bind
    - socket.listen
"""


server.serve_forever()

 

posted @ 2019-07-16 22:29  P-Z-W  阅读(124)  评论(0编辑  收藏  举报