Creating multithreaded Classes

Source: Internet
Author: User

#-*-coding:cp936-*-#python#Xiaodeng#http://www.cnblogs.com/fnng/p/3489321.html#Creating multithreaded ClassesImportThreading fromTimeImportSleep,ctimeclassMyThread (Threading. Thread):#Threading. Thread    'creates a Mythread class for inheriting threading. Thread class.'    def __init__(self,func,args,name="'):        'initializes parameters such as Func, args, name, and so on, using the class's initialization method.'Threading. Thread.__init__(self) self.func=func Self.args=args Self.name=namedefRun (self): Apply (Self.func,self.args)defSuper_play (file,time): forIinchRange (2):        Print 'Start playing:%s.%s'%(File,ctime ()) Sleep (time) dict={u'love business. mp3': 3,u'The Great Qin Empire. mp4': 5}#Creating Threadsthreads=[]files=Range (len (dict)) forKvinchDict.items ():PrintSuper_play.__name__#Super_play    #MyThread (Super_play, (k,v), super_play.__name__)T=mythread (Super_play, (k,v), Super_play.__name__) threads.append (t)if __name__=='__main__':    #Start Thread     forIinchFiles:threads[i].start () forIinchFiles:threads[i].join ()#Main Thread    Print 'end:%s'%ctime ()

Creating multithreaded Classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.