标签:har accept == from 进程 dea ssi user ESS
进程:
感觉只是使用Process模块加以使用即可:
# -*- coding: utf-8 -*- # data:2019-02-23 21:23 # user:DIY # file:thread_master.py from socket import * from multiprocessing import Process from time import sleep def dealWithClient(newSocket,destAddr): while True: recvData = newSocket.recv(1024) if recvData: print(‘recv[%s]:[%s]‘ %(str(destAddr),recvData.decode())) else: print(‘[%s]客户端已经关闭‘%(str(destAddr))) break newSocket.close() def main(): serSocket = socket(AF_INET,SOCK_STREAM) serSocket.setsockopt(SOL_SOCKET,SO_REUSEADDR,1) localAddr = (‘‘,7788) serSocket.bind(localAddr) serSocket.listen(5) try: while True: print(‘----主进程等待新客户端的到来---‘) newSocket,destAddr = serSocket.accept() print(‘---主进程接来下创建一个新的进程负责数据处理数据[%s]‘ %str(destAddr)) client = Process(target=dealWithClient,args=(newSocket,destAddr)) client.start() newSocket.close() finally: serSocket.close() if __name__ == ‘__main__‘: main()
标签:har accept == from 进程 dea ssi user ESS
原文地址:https://www.cnblogs.com/tengfei520/p/10425264.html