Python源码示例:queue.task_done()

示例1
def consumer(queue, stack, apix=1.0, iothreads=None):
    log = logging.getLogger('root')
    with mrc.ZSliceWriter(stack, psz=apix) as zwriter:
        while True:
            log.debug("Get")
            i, ri = queue.get(block=True)
            log.debug("Got %d, queue for %s is size %d" %
                      (i, stack, queue.qsize()))
            if i == -1:
                break
            new_image = ri.get()
            log.debug("Result for %d was shape (%d,%d)" %
                      (i, new_image.shape[0], new_image.shape[1]))
            zwriter.write(new_image)
            queue.task_done()
            log.debug("Wrote %d to %d@%s" % (i, zwriter.i, stack))
    if iothreads is not None:
        iothreads.release() 
示例2
def myTask(queue):
  value = queue.get()
  print("Process {} Popped {} from the shared Queue".format(multiprocessing.current_process().pid, value))
  queue.task_done() 
示例3
def mySubscriber(queue):
  while not queue.empty():
    item = queue.get()
    if item is None:
      break
    print("{} removed {} from the queue".format(threading.current_thread(), item))
    queue.task_done()
    time.sleep(1) 
示例4
def mySubscriber(queue):
  while True:
    item = queue.get()
    if item is None:
      break
    print("{} removed {} from the queue".format(threading.current_thread(), item))
    print("Queue Size is now: {}".format(queue.qsize()))
    queue.task_done() 
示例5
def mySubscriber(queue):
  while not queue.empty():
    item = queue.get()
    if item is None:
      break
    print("{} removed {} from the queue".format(threading.current_thread(), item))
    queue.task_done() 
示例6
def mySubscriber(queue):
  time.sleep(1)
  while not queue.empty():
    item = queue.get()
    if item is None:
      break
    print("{} removed {} from the queue".format(threading.current_thread(), item))
    queue.task_done() 
示例7
def worker(c):
    thread = threading.currentThread()
    if queue.empty():
        return
    json_file = queue.get()
    config = json_file.replace(".json","")
    c.run(config)
    worker(c)
    queue.task_done()
    logging.debug('Done') 
示例8
def task_done(self) -> None: ... 
示例9
def iter_queue(queue: TypedQueue[Optional[T]]) -> Generator[T, None, None]:
    """Yield items from a queue"""
    while True:
        record = queue.get()
        try:
            # Queue is finished, nothing more will arrive
            if record is None:
                return
            yield record
        finally:
            queue.task_done() 
示例10
def run(self):
        while True:
            im = queue.get()
            if im is None:
                queue.task_done()
                sys.stdout.write("x")
                break
            f = io.BytesIO()
            im.save(f, test_format, optimize=1)
            data = f.getvalue()
            result.append(len(data))
            im = Image.open(io.BytesIO(data))
            im.load()
            sys.stdout.write(".")
            queue.task_done() 
示例11
def request_task(self, queue, setup_or_state_change_or_validation, test_functions, test_iteration):
        try:
            # Table data does not provide ability to inject unique agent_id's for each concurrent instance.
            # The queue stores unique agent_id objects, injected by the new_thread function.
            # Get the agent_id from the Queue and modify the original table data to change the agent_id to something unique.
            http_request_body_tag = test_functions.get("http_request_body")
            http_request_body_file_tag = test_functions.get("http_request_body_file")
            if http_request_body_tag != None and http_request_body_file_tag != None :
                self.fail("Test " + self._testMethodName + ":" + test_functions["function_name"] + " contains both http_request_body and http_request_body_file tags." )

            thedata = ''
            if http_request_body_tag == None and http_request_body_file_tag != None:
                thedata = open(http_request_body_file_tag).read()
            else:
                thedata=http_request_body_tag

            the_uid = queue.get()
            jsondata = json.loads(thedata)
            jsondata['agent_id'] = the_uid
            newdata = json.dumps(jsondata)

            # call the inline task passing the new data with the unique agent_id
            self.execute_the_test(setup_or_state_change_or_validation, test_functions, test_iteration )

        except Exception as e:
            self.fail("Test " + self._testMethodName + ":" + test_functions["function_name"] + ", unexpected exception error: %s"%e )
        finally:
            queue.task_done() 
示例12
def download_worker():
    while True:
        url = queue.get()
        download_file(url, SAVE_DIR)
        queue.task_done()

# Returns the path of the specified page number 
示例13
def write_buffer(buffer):
    for item in buffer:
        try:
            item['fn'](*item.get('args', ()), **item.get('kw', {}))
        except:
            log.exception(
                'Exception while processing queue item: {}'
                .format(item))
        queue.task_done()