zoukankan      html  css  js  c++  java
  • pyhton3多线程

    from time import ctime,sleep

    def music():
    for i in range(2):
    print ("I was listening to music. %s" %ctime())
    sleep(1)

    def move():
    for i in range(2):
    print ("I was at the movies! %s" %ctime())
    sleep(5)

    if __name__ == '__main__':
    music()
    move()
    print ("all over %s" %ctime())

    import threading
    from time import ctime,sleep

    def music(func):
    for i in range(2):
    print ("I was listening to %s. %s" %(func,ctime()))
    sleep(1)

    def move(func):
    for i in range(2):
    print ("I was at the %s! %s" %(func,ctime()))
    sleep(5)

    if __name__ == '__main__':
    music("test1")
    move("test2")

    print ("all over %s" %ctime())

    #coding=utf-8
    import threading
    from time import ctime,sleep


    def music(func):
    for i in range(2):
    print("I was listening to %s. %s" %(func,ctime()))
    sleep(1)

    def move(func):
    for i in range(2):
    print ("I was at the %s! %s" %(func,ctime()))
    sleep(5)

    threads = []
    t1 = threading.Thread(target=music,args=(u'test1',))
    threads.append(t1)
    t2 = threading.Thread(target=move,args=(u'Test2',))
    threads.append(t2)

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

    print ("all over %s" %ctime())

    第三部分线程任务处理。

  • 相关阅读:
    抽象代数学习笔记
    WC2021 游记
    简单的数学题
    前缀和公式
    杜教筛
    [模板]BZOJ4756线段树合并
    SPOJ 694
    bzoj1367 可并堆
    莫比乌斯反演(理论)
    es6 Set数据结构
  • 原文地址:https://www.cnblogs.com/wcLT/p/4305607.html
Copyright © 2011-2022 走看看