파이썬 네트워크 프로그래밍 스레드 (중국 상인 기술 펜 질문 지점)

주제는 다소 아마도 (스레드, 쿨, 수선을 검토하지 않음), 거의 그렇게 될 출력 4 개 개의 스레드를 생성, 잊어

================= RESTART : /home/cmy/python/Internet/fuxi.py =================
시작 스레드 1 :
시작 쓰레드 1 : 2
시작 스레드 1 : 3
시작 스레드 1 : 4
개시 스레드 1 : 5

스레드 시작 2 : 6
시작 스레드 2 : 7
시작 스레드 2 : 8
시작 스레드 2 : 9
시작 스레드 2시 10분

시작 3시 11분 스레드
시작 스레드 3시 12분
시작 스레드 3시 13분
시작 스레드 3시 14분
시작 스레드 3:15

시작 4시 16분 스레드
시작 스레드 4시 17분
시작 스레드 4시 18분
시작 스레드 4시 19분
시작 스레드 4:20

 

코드

수입 스레딩 
수입 시간 
스레드 로크 = threading.Lock과 () 
스레드 = [] 
I = 1 개 
클래스 myThread (threading.Thread) : 
    데프 __init __ (자기 이름) : 
        threading.Thread .__ 초기화 __ (자기) 
        self.name = 이름 
    데프 실행 ( 자기) 
        threadlock.acquire () 
        print_out (self.name) 
        threadlock.release () 
DEF print_out (명칭) : 
    글로벌 내가 
    카운트 = 0 
    동안 카운트 <5 : 
        인쇄 ( "开始线程"이름 ","I) 
        + = 1 카운트 
        I + = 1 
    인쇄 ( "") 
thread1 myThread = ( '1') 
thread2 myThread = ( '2') 
thread3 myThread = ( '3') 
thread4 myThread = ( '4')) 
thread1.start () 
thread2.start () 
thread3.start () 
thread4.start () 
threads.append (thread1) 
threads.append (thread2) 
threads.append (thread3) 
threads.append (thread4) 
스레드에 대한 t : 
    t .붙다()

  

 

추천

출처www.cnblogs.com/chenminyu/p/11712250.html