Python Queue.LifoQueue() Examples
The following are 19
code examples of Queue.LifoQueue().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Queue
, or try the search function
.
Example #1
Source File: dataloader_webcam.py From video-to-pose3D with MIT License | 6 votes |
def __init__(self, webcam = 0, batchSize=1, queueSize=256): # 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.stream = cv2.VideoCapture(int(webcam)) assert self.stream.isOpened(), 'Cannot open webcam' self.stopped = False self.batchSize = batchSize # initialize the queue used to store frames read from # the video file self.Q = LifoQueue(maxsize=queueSize)
Example #2
Source File: dataloader_webcam.py From video-to-pose3D with MIT License | 6 votes |
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)
Example #3
Source File: pipeline_viewer.py From logstash-parsers with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: telemetry.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self): self._queue = Queue.LifoQueue() self._failedque = deque() self._http_session = requests.Session() self._http_offline = False self._workers = []
Example #5
Source File: GlobalData.py From MSpider with GNU General Public License v2.0 | 5 votes |
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()
Example #6
Source File: dataloader.py From video-to-pose3D with MIT License | 5 votes |
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)
Example #7
Source File: dataloader_webcam.py From video-to-pose3D with MIT License | 5 votes |
def __init__(self, detectionLoader, queueSize=1024): # initialize the file video stream along with the boolean # used to indicate if the thread should be stopped or not self.detectionLoader = detectionLoader self.stopped = False # initialize the queue used to store data self.Q = LifoQueue(maxsize=queueSize)
Example #8
Source File: dataloader_webcam.py From video-to-pose3D with MIT License | 5 votes |
def __init__(self, webcam, batchSize=1, 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.batchSize = batchSize self.Q = LifoQueue(maxsize=queueSize)
Example #9
Source File: pool.py From TcpRoute with GNU General Public License v2.0 | 5 votes |
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
Example #10
Source File: encode.py From scipher with MIT License | 5 votes |
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 '('
Example #11
Source File: brutal_SSH.py From Brutal_SSH with MIT License | 5 votes |
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
Example #12
Source File: test_queue.py From gcblue with BSD 3-Clause "New" or "Revised" License | 4 votes |
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',))
Example #13
Source File: video_pipeline.py From edusense with BSD 3-Clause "New" or "Revised" License | 4 votes |
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()
Example #14
Source File: test_queue.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
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',))
Example #15
Source File: brutedns.py From subdomain3 with MIT License | 4 votes |
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()
Example #16
Source File: test_queue.py From oss-ftp with MIT License | 4 votes |
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',))
Example #17
Source File: test_queue.py From BinderFilter with MIT License | 4 votes |
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',))
Example #18
Source File: test_queue.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
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',))
Example #19
Source File: test_queue.py From ironpython2 with Apache License 2.0 | 4 votes |
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',))