zoukankan      html  css  js  c++  java
  • python之通过thread来实现多进程

    代码如下:
    import threading, time
    
    class Test1(threading.Thread):
      def __init__(self, name):
        super().__init__(name=name)
    
      def run(self):
        print('test1 start')
        time.sleep(2)
        print('test1 end')
    
    
    class Test2(threading.Thread):
      def __init__(self, name):
        super().__init__(name=name)
    
      # 继承thread必须覆盖的方法
      def run(self):   
        print('test2 start')
        time.sleep(4)
        print('test2 end')
    
    
    if __name__ == '__main__':
      thread1 = Test1('test1')
      thread2 = Test2('test2')
      start_time = time.time()
      thread1.start()   
      thread2.start()
    
      # 使用join方法,这两个线程就会阻塞主线程的运行,print('main')就会后执行
      thread1.join()   
      thread2.join()
      print('main')
    
    
    结果:

  • 相关阅读:
    这之后的事。。。
    POJ
    POJ
    博客园的装饰
    高斯消元
    逆序数技巧
    各种小的 dp (精)
    最大区间和变形
    树dp 统计异或值
    dp
  • 原文地址:https://www.cnblogs.com/raind/p/10187930.html
Copyright © 2011-2022 走看看