python-Thread Queue

Source: Internet
Author: User

A queue is a data structure that is secure and data-safe. The list of capable things in the queue is capable. The list is thread insecure, so it can be said that the queue is for multithreaded occurrences.

The data structure is used to store it, except that the various data structures are stored in different ways. For example: Collections, queues, mappings

List: Storing by index value

Dictionary: A hash table stored by key value

List.pop () #按索引删除

List.remove (' str ') #按值删除

Import # Thread Queue Q # default FIFO  q=queue. Queue (5) can only put 5 elements q.put (q.put) ('hello') q.put ({'  name':'Lee'})
Print (Q.qsize ())
Print (Q.full ())
Print (Q.empty ())
 while  1: Data  = q.get ()  print   print  ( " ------ "  )
Import Queueq=queue. Lifoqueue ()  # LIFO mode q.put (a) q.put ('hello') q.put ( {'name':'Lee'})
Print (Q.qsize ())
Print (Q.full ())
Print (Q.empty ())
 while 1: Data=printprint('------' )
Import queue
Q=queue. Priorityqueue () #优先级模式
Q.put ([3,12])
Q.put ([2, ' hello '])
Q.put ([4,{' name ': ' Lee '}])

Print (Q.qsize ())
Print (Q.full ())
Print (Q.empty ())
While 1:
Data=q.get (block=false) #相当于q. get_nowait ()
Print (data)
Print ('------')

Q.join () #意味着等待队列为空, and then perform another operation

python-Thread Queue

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.