Python多线程

上一篇 / 下一篇  2017-08-10 15:01:44 / 个人分类:Python

Python多线程
==============================================
from time import ctime,sleep
import threading

def listen(content,loop):
    for i in range(loop):
        print("&&&&&Start to listen~ %s %s" %(content, ctime()))
        sleep(1);


def talk(content , loop):
    for i in range(loop):
        print("###Start to talk~ %s %s" %(content, ctime()))
        sleep(5);


def write(content, loop):
    for i in range(loop):
        print("****start to write ~~ %s %s" %(content,ctime()))
        sleep(10)

threads = []
th0 = threading.Thread(target = listen,args = ("listen: OMG",5))
threads.append(th0)
th1 = threading.Thread(target = talk,args = ("Talk: Hello",5))
threads.append(th1)
th2 = threading.Thread(target = write,args = ("Write: Life is short, you need python",5))
threads.append(th2)


if __name__ == '__main__':
    for t in threads:
        t.start()

    for t in threads:
        t.join()
print("The end ! %s" %ctime())


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar