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())

    第三部分线程任务处理。

  • 相关阅读:
    ptrace
    CentOS 5.4 final下Systemtap的安装
    SystemTap 静态探针安装包
    sysdig
    ORACLE 内部原理
    An introduction to KProbes
    CentOS6.5升级手动安装GCC4.8.2 与 CentOS 6.4 编译安装 gcc 4.8.1
    在Oracle Linux上安装dtrace
    dwarf调试信息格式入门
    MySQL 5.6.20-4 and Oracle Linux DTrace
  • 原文地址:https://www.cnblogs.com/wcLT/p/4305607.html
Copyright © 2011-2022 走看看