python 多线程threading

#!/usr/bin/env python

#-*- coding:utf-8 -*-

import time

import threading


def worker(id):

    print 'id=',id

    

    

class Task(object):

    def __call__(self,id):

        print 'TASk:%s'% id

        

t = Task()        

for i in range(5):

    t1 = threading.Thread(target=t,args=(1,))   #参数值是元祖后面跟,逗号  target 可以是类名或者函数名 注意如果是类的话需要重写类的call 方法

    t1.start()


你可能感兴趣的:(python 多线程threading)