• Python自定义线程类简单示例


    Python自定义线程类简单示例

    这篇文章主要介绍了Python自定义线程类,结合简单实例形式分析Python线程的定义与调用相关操作技巧,需要的朋友可以参考下。具体如下:
    一. 代码    
    # -*- coding:utf-8 -*-
    #! python2
    import threading
    class mythread(threading.Thread):
      def __init__(self, num):
        threading.Thread.__init__(self)
        self.num = num
      def run(self):
        print('I am {0}'.format(self.num))
    t1 = mythread(1)
    t2 = mythread(2)
    t3 = mythread(3)
    t1.start()
    t2.start()

    t3.start()


    二. 运行结果

  • 相关阅读:
    20210312
    20210311
    20210310
    例5-1
    例5-2
    例4-12-2
    例4-12
    例4-11
    例4-10
    例4-9
  • 原文地址:https://www.cnblogs.com/amengduo/p/9586394.html
Copyright © 2020-2023  润新知