本文整理匯總了Python中Queue.LifoQueue方法的典型用法代碼示例。如果您正苦於以下問題:Python Queue.LifoQueue方法的具體用法?Python Queue.LifoQueue怎麽用?Python Queue.LifoQueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Queue
的用法示例。
在下文中一共展示了Queue.LifoQueue方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parenthesis
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def parenthesis(x):
q=Queue.LifoQueue()
p1={}
p2={}
for i in xrange(len(x)):
if x[i] in ['(', '[', '{']:
q.put(i);
continue
if x[i] in [')', ']', '}']:
if(q.empty()==True):
return (None, None)
k=q.get(False)
p1[k]=i
p2[i]=k
continue
return (p1, p2)
示例2: __init__
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def __init__(self, dataloder, batchSize=1, queueSize=1024):
# initialize the file video stream along with the boolean
# used to indicate if the thread should be stopped or not
self.det_model = Darknet("yolo/cfg/yolov3-spp.cfg")
self.det_model.load_weights('models/yolo/yolov3-spp.weights')
self.det_model.net_info['height'] = opt.inp_dim
self.det_inp_dim = int(self.det_model.net_info['height'])
assert self.det_inp_dim % 32 == 0
assert self.det_inp_dim > 32
self.det_model.cuda()
self.det_model.eval()
self.stopped = False
self.dataloder = dataloder
self.batchSize = batchSize
# initialize the queue used to store frames read from
# the video file
self.Q = LifoQueue(maxsize=queueSize)
示例3: __init__
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def __init__(self):
self._queue = Queue.LifoQueue()
self._failedque = deque()
self._http_session = requests.Session()
self._http_offline = False
self._workers = []
示例4: __init__
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def __init__(self):
self.__version__ = "1.0"
self.host_ip = ""
self.host_port = 22
self.usernames = Queue.LifoQueue()
self.passwords = Queue.LifoQueue()
self.password_list = []
self.threads = 4
self.timeout = 5
示例5: expand_all
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def expand_all(grammar, nonterm, state):
result = ""
queue = Queue.LifoQueue()
queue.put_nowait(nonterm)
# do this iteratively; recursively blows past python's recursive limit
in_list = None
len_at_start_of_list = 0
while not queue.empty():
head = queue.get_nowait()
# Keep track of being in a list until all the bits for the list
# have been used up
if head in state.list_bits:
in_list = head
len_at_start_of_list = queue.qsize()
# done with the list once we consume the next item in the queue
if in_list and queue.qsize() < len_at_start_of_list:
in_list = None
terms = expand(grammar, head, state, in_list)
if len(terms) == 0:
if isinstance(head, basestring):
result = " ".join([result, head])
else:
result = " ".join([result, str(head)])
else :
# put them into the lifo queue backwards, so we'll get the
# first one out
for nt in reversed(terms):
if nt in state.common.append_newlines():
queue.put_nowait(nltk.Nonterminal("\n"))
queue.put_nowait(nt)
return result
# Must be determinstically reversible by the decoder, so use the
# following rules:
# 1) Erase spaces at the beginning and end of every line
# 2) If the first letter of the line is not capitalized, make it so
# 3) remove one space before all punctuation (except '(')
# 4) remove one space after '('
示例6: _put_conn
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def _put_conn(self, host, port, sock):
u""" 將連接添加回連接池
會檢查連接狀態,不正常的連接會被拋棄。
"""
if hasattr(self.sock_mod, "get_display_name"):
sock_name = self.sock_mod.get_display_name()
else:
sock_name = None
sock_info = 'sock_mod:%s host:%s port:%s' % (sock_name, host, port)
if sock:
if is_connection_dropped(sock):
logging.debug(u'已關閉連接無法添加回連接池。%s' % sock_info)
try:
sock.close()
except:
pass
else:
with self.lock:
site_connes = self.site_dict.get(u'%s:%s' % (host, port), None)
if site_connes is None:
site_connes = LifoQueue(self.max_site_conn)
try:
site_connes.put(sock)
logging.debug(u'添加連接回連接池。 %s' % sock_info)
except Full:
logging.debug(u'連接池滿. %s' % sock_info)
try:
sock.close()
except:
pass
return
self.site_dict[u'%s:%s' % (host, port)] = site_connes
示例7: __init__
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def __init__(self, webcam, queueSize=256):
# initialize the file video stream along with the boolean
# used to indicate if the thread should be stopped or not
self.stream = cv2.VideoCapture(int(webcam))
assert self.stream.isOpened(), 'Cannot capture source'
self.stopped = False
# initialize the queue used to store frames read from
# the video file
self.Q = LifoQueue(maxsize=queueSize)
示例8: set_urlnode_queue
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def set_urlnode_queue(self):
if self.spider_policy == 1:
self.spider_urlnode_queue = Queue.LifoQueue()
elif self.spider_policy == 2:
self.spider_urlnode_queue = Queue.PriorityQueue()
else:
self.spider_urlnode_queue = Queue.Queue()
示例9: simple_queue_test
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def simple_queue_test(self, q):
if not q.empty():
raise RuntimeError, "Call this function with an empty queue"
# I guess we better check things actually queue correctly a little :)
q.put(111)
q.put(333)
q.put(222)
target_order = dict(Queue = [111, 333, 222],
LifoQueue = [222, 333, 111],
PriorityQueue = [111, 222, 333])
actual_order = [q.get(), q.get(), q.get()]
self.assertEqual(actual_order, target_order[q.__class__.__name__],
"Didn't seem to queue the correct data!")
for i in range(QUEUE_SIZE-1):
q.put(i)
self.assertTrue(not q.empty(), "Queue should not be empty")
self.assertTrue(not q.full(), "Queue should not be full")
last = 2 * QUEUE_SIZE
full = 3 * 2 * QUEUE_SIZE
q.put(last)
self.assertTrue(q.full(), "Queue should be full")
try:
q.put(full, block=0)
self.fail("Didn't appear to block with a full queue")
except Queue.Full:
pass
try:
q.put(full, timeout=0.01)
self.fail("Didn't appear to time-out with a full queue")
except Queue.Full:
pass
# Test a blocking put
self.do_blocking_test(q.put, (full,), q.get, ())
self.do_blocking_test(q.put, (full, True, 10), q.get, ())
# Empty it
for i in range(QUEUE_SIZE):
q.get()
self.assertTrue(q.empty(), "Queue should be empty")
try:
q.get(block=0)
self.fail("Didn't appear to block with an empty queue")
except Queue.Empty:
pass
try:
q.get(timeout=0.01)
self.fail("Didn't appear to time-out with an empty queue")
except Queue.Empty:
pass
# Test a blocking get
self.do_blocking_test(q.get, (), q.put, ('empty',))
self.do_blocking_test(q.get, (True, 10), q.put, ('empty',))
示例10: __init__
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def __init__(self, args):
self.target_domain = args.domain
self.cname_flag = args.cname
if not (self.target_domain):
print('usage: brutedns.py -h')
sys.exit(1)
self.check_env()
self.level = args.level
self.sub_dict = args.sub_file
self.speed = args.speed
self.default_dns = True if args.default_dns is "y" else False
self.next_sub_dict = args.next_sub_file
self.other_result = args.other_file
self.timeout = 10
self.resolver = dns.resolver.Resolver(configure=self.default_dns)
self.resolver.lifetime = self.timeout
self.resolver.timeout = self.timeout
self.found_count = 0
self.next_found_count = 0
self.cmdline = ""
self.queues = LifoQueue()
self.queue_sub = Queue()
self.cdn_set = set()
self.cname_set = set()
self.white_filter_subdomain = set()
self.cname_block_dict = dict()
self.ip_block_dict = dict()
self.ip_all_dict = dict()
self.ip_flag_dict = dict()
self.active_ip_dict = dict()
self.ip_count_dict = dict()
self.black_ip = set()
self.set_next_sub = self.load_next_sub_dict()
self.set_cdn = self.load_cdn()
self.load_sub_dict_to_queue()
self.extract_next_sub_log()
self.segment_num = self.judge_speed(self.speed)
if not self.default_dns:
self.nameservers = self.load_nameservers()
self.check_nameservers()
示例11: run_pipeline
# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import LifoQueue [as 別名]
def run_pipeline(server_address, time_duration, process_real_time,
process_gaze, keep_frame_number, channel, area_of_interest,
fps,start_date,start_time,backend_params=None,
file_params=None, profile=False):
# initialize queues
q = None
if process_real_time:
q = queue.LifoQueue()
else:
# queue size 1 for now
q = queue.Queue(1)
# initialize socket reader thread, this thread multiplexes multiple queues
# for the sake of simplicity, it is one producer, multiple consumer design
reader_thread = SocketReaderThread(q, server_address, keep_frame_number,
profile)
# initialize video consumers
consumer_thread = ConsumerThread(q, process_real_time, process_gaze,
channel, area_of_interest, fps,start_date,start_time,
backend_params,file_params, profile)
# start downstream (consumers)
consumer_thread.start()
# then, start upstream (producer)
reader_thread.start()
# run forever if duration is negative
if time_duration < 0:
# this only works python 3.2+ and on linux
# threading.Event().wait()
# wait for reader to finish
reader_thread.join()
# wait for consumer thread to finish
consumer_thread.stop()
consumer_thread.join()
else: # shutdown after time_duration seconds
time.sleep(time_duration)
# terminate upstream
reader_thread.stop()
# join the upstream
reader_thread.join()
# terminate downstream
consumer_thread.stop()
# join the downstream
consumer_thread.join()