zoukankan      html  css  js  c++  java
  • python 中线程

    import threading
    import time

    class Test(threading.Thread):
        # 继承threading.Thread
        def __init___(self):
            super(Test, self).__init__()

        def run(self):
            # 设置线程方法
            threadname = threading.currentThread().getName()
            for x in xrange(10):
                print threadname, x, 
                print 
                time.sleep(1)
                

    threads = []
    for i in xrange(1, 5):
        threads.append(Test())

    for t in threads:
        #启动线程
        t.start()

    # 主线程中等待所有子线程退出
    for i in threads:
        t.join() # 线程完成

    # 如果不加上面t.join,将会一直等待下去,无法打印出end

    print  'end'

    如果你的主线程中有别的事情要做,就无需加join,加join只是告诉主线程,所有子线程已经完成
            

  • 相关阅读:
    HDU 2757 Ocean Currents
    HDU 2704 Bulletin Board
    HDU 2234 无题I
    HDU 3638 Go , SuSu
    HDU 1199 Color the Ball
    HDU 1430 魔板
    PL/SQL例外的介绍
    表分区介绍
    移动表空间数据文件
    long\lob\bfile类型介绍
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429467.html
Copyright © 2011-2022 走看看