Several PythonStudy-- thread message queue

Queue

from Queue Import Queue, LifoQueue, PriorityQueue 

# queue module Queue 
# Class Queue 
# Class LifoQueue 
# Class PriorityQueue 

# JoinableQueue use with the process, but not exactly the same as in the IPC 

Q = Queue () 

# into elements put method 
q.put ( " 123 " ) 
q.put ( " 456 " ) 
q.put ( " 789 " ) 

# remove elements get method 
# method (Basic value) 
Print (q.get ())
 Print (q.get ()) 

# method two (Premium value) 
#Set blocking options block by default True) 
# Set the timeout option for the default timeout None 
# If the timeout to take in the obstruction case is less than the value, an exception is thrown 
# GET (Self, block = True, timeout = None) 
Print (q.get (block = True, timeout =. 1 )) 

# inform queue task completion 
q.task_done ()
 # priority queue to complete the current task can be completed blocked 
# q.join () 
from queue Import queue, LifoQueue, PriorityQueue 

# queue module queue 
# class Queue 
# class LifoQueue 
# class PriorityQueue 

# identical but without the IPC use JoinableQueue process 

Q = Queue () 

# into elements put method 
q.put (" 123 " ) 
q.put ( " 456 " ) 
q.put ( " 789 " ) 

# remove elements get method 
# method (Basic value) 
Print (q.get ())
 Print (q.get ()) 

# method II (Premium value) 
# set the blocking option to block default is True) 
# set the timeout option for the default timeout None 
# If the timeout to take in the obstruction case is less than the value, an exception is thrown 
# GET (Self, block = True , timeout = None) 
Print (q.get (Block = True, timeout = 1 )) 

# notify queue task is completed 
q.task_done ()
 # priority queue to complete the current task can be completed obstructive 
# q.join ()

LifoQueue

from Queue Import LifoQueue 

# Last in First OUT 
# LIFO queue 
# last-out stack simulation 
# in addition to other sequences are the same 
lifoqueue = LifoQueue () 

lifoqueue.put ( " 123 " ) 
lifoqueue.put ( " 456 " ) 
lifoqueue. PUT ( " 789 " ) 

Print (lifoqueue.get ())
 Print (lifoqueue.get ())
 Print (lifoqueue.get ())

PriorityQueue

from Queue Import PriorityQueue 


# includes a priority queue 
# may be stored in a comparison of the target 
# comparison result of the higher priority the smaller 
# custom objects unless defined __eq__ method, otherwise it is impossible to compare ( You can not use comparison operators) can not be stored 

# PQ = PriorityQueue () 
# pq.put ( "222") 
# pq.put ( "111") 
# pq.put ( "333") 
# pq.put (34234) 
# TypeError: '<' Not Supported BETWEEN instances of 'int' and 'STR' 
# necessary to ensure the internal value stored in a priority queue is the same type 

# Print (pq.get ()) 
# Print (pq.get ()) 
# Print (pq.get ()) 


# class analog comparison operation 
class Aa (Object):
    # Initialization 
    DEF  the __init__ (Self, NUM): 
        self.num = NUM 

    # less than Within last operation Litter 
    DEF  __lt__ (Self, OTHER):
         return self.num <other.num, " less than " 

    # less equal Litter 
    DEF  __le__ (Self, OTHER):
         return self.num <= other.num, " less " 

    # greater than Within last operation Greater 
    DEF  __gt__ (Self, OTHER):
         return self.num> other.num, " greater than " 

    # than or equal to equal Greater 
    DEF __ge__ (Self, OTHER):
         return self.num> = other.num, " not less than " 

    # equal arithmetic equal 
    DEF  __eq__ (Self, OTHER):
         return self.num == other.num, " equal to " 

    # does not equal equal 
    DEF  __ne__ (Self, OTHER):
         return ! self.num = other.num, " not equal to " 

Print (Aa (100)> = Aa (200 is ))
 Print (Aa (100) <= Aa (200 is ))
 Print (Aa (100)> Aa (200 is ))
 Print (Aa (100) <Aa (200 is ))
 Print(Aa (100)! = Aa (200 is ))
 Print (Aa (100) == Aa (200 is ))
 # (False, "greater than or equal ') 
# (True,' less') 
# (False, 'greater than' ) 
# (True, 'less than') 
# (True, 'not equal') 
# (False, 'equal')

 

Guess you like

Origin www.cnblogs.com/tingguoguoyo/p/10990755.html