Python threading Knowledge re-learning a

Source: Internet
Author: User

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

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.