您的位置:首页 > 编程语言 > Python开发

Python RuntimeError: thread.__init__() not called

2015-08-25 17:15 811 查看
直接上代码:

# encoding: UTF-8

import threading

import time

class MyThread(threading.Thread):

    def run(self):

        for i in range(3):

            time.sleep(1)

            msg = "I'm "+self.ip+' @ '+str(i)

            print msg

    def __init__(self,ip):

        threading.Thread.__init__(self)       //没有该语句的话则会出现Python RuntimeError: thread.__init__() not called异常

        self.ip = ip

        

def test():

    for i in range(5):

        t = MyThread("hello"+str(i))

        t.start()

if __name__ == '__main__':

    test()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: