直接上代码:
代码语言:javascript复制# 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()