After reading the Linux threads, syncing, information numbers and so on, it feels different to understand the Python thread before.
Make some tests.
Thread: The module provides basic threading and lock support
Threading: Provides higher-level, more functional thread management capabilities
Queue: Allows a user to create a data structure that can be used to share information between multiple threads
#!/usr/bin/env python#-*-coding:utf-8-*-ImportThread fromTimeImportSleep, Ctimeloops= [4,2]defLoop (Nloop, Nsec, lock):Print 'Start Loop', Nloop,'At :', CTime () sleep (nsec)Print 'Loop', Nloop,'Done at :', CTime () lock.release ()defMain ():Print 'starting at:', CTime () locks=[] Nloops=Range (len (loops)) forIinchNloops:lock=Thread.allocate_lock () Lock.acquire () Locks.append (lock) forIinchNloops:thread.start_new_thread (Loop, (I,loops[i],locks[i])) forIinchNloops: whilelocks[i].locked ():Pass Print 'All do at :', CTime ()if __name__=='__main__': Main ()
Python threading Knowledge re-learning a