當前位置: 首頁>>代碼示例>>Python>>正文


Python queue.JoinableQueue類代碼示例

本文整理匯總了Python中gevent.queue.JoinableQueue的典型用法代碼示例。如果您正苦於以下問題:Python JoinableQueue類的具體用法?Python JoinableQueue怎麽用?Python JoinableQueue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了JoinableQueue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Speaker

class Speaker(gevent.Greenlet):
    RATE = 44100

    def __init__(self, rcv):
        gevent.Greenlet.__init__(self)
        self.rcv = rcv
        PA = pyaudio.PyAudio()
        self.pa= PA.open(
            format= pyaudio.paInt16,
            channels= 1,
            rate= self.RATE,
            output= True
        )
        self.queue = JoinableQueue()

    def _run(self):
        print 'spk_on'
        while True:
            try:
                buf = self.rcv.queue.get()
            except gevent.queue.Empty:
                buf = '\0'
##            print '.',
            self.pa.write(buf)
            time.sleep(0.0001)

        self.queue.task_done()
        self.pa.close()
開發者ID:jorjun,項目名稱:project_jukenode,代碼行數:28,代碼來源:server.py

示例2: __init__

    def __init__(self, *args, **kwargs):
        super(InterceptedStreamsMixin, self).__init__(*args, **kwargs)
        self.stdout_callbacks = []
        self.stdout_queue = JoinableQueue()

        self.stderr_callbacks = []
        self.stderr_queue = JoinableQueue()
開發者ID:miohtama,項目名稱:py-geth,代碼行數:7,代碼來源:mixins.py

示例3: test_service

def test_service():
    "Service() should implement the basic needs of an async service"

    # Given the following service
    class MyService(Service):
        def __init__(self, my_mock, result_queue=None):
            self.my_mock = my_mock
            super(MyService, self).__init__(
                callback=self.run,
                result_queue=result_queue,
            )

        def run(self, package, sender_data):
            self.my_mock.ran = package

    my_mock = Mock()
    queue = JoinableQueue()
    service = MyService(my_mock, result_queue=queue)

    # When I queue a package to be processed by my service and start the
    # service with 1 concurrent worker
    service.queue('gherkin==0.1.0', 'main')
    service.consume()

    # Then I see that the package processed
    package = queue.get()
    package.should.equal('gherkin==0.1.0')

    my_mock.ran.should.equal('gherkin==0.1.0')
開發者ID:pombredanne,項目名稱:curdling,代碼行數:29,代碼來源:test_main.py

示例4: test_service_failure

def test_service_failure():
    "Service() should handle custom callback failures"

    # Given the following service
    class MyService(Service):
        def __init__(self, result_queue=None):
            super(MyService, self).__init__(
                callback=self.run,
                result_queue=result_queue,
            )

        def run(self, package, sender_data):
            raise ValueError("I don't want to do anything")

    queue = JoinableQueue()
    service = MyService(result_queue=queue)

    # When I queue a package to be processed by my service and start the
    # service with 1 concurrent worker
    service.queue('gherkin==0.1.0', 'main')
    service.consume()
    service.pool.join()         # Ensure we finish spawning the greenlet

    # Then I see that no package was processed
    queue.qsize().should.equal(0)

    # And that the list of failed packages was updated
    service.failed_queue[0][0].should.equal('gherkin==0.1.0')
    service.failed_queue[0][1].should.be.a(ValueError)
    service.failed_queue[0][1].message.should.equal("I don't want to do anything")
開發者ID:pombredanne,項目名稱:curdling,代碼行數:30,代碼來源:test_main.py

示例5: handle

def handle():
    connection = create_postgresql_connection()

    cursor = connection.cursor()
    cursor.execute("BEGIN;")
    cursor.execute("DELETE FROM core_ratequery;")
    cursor.execute("COMMIT;")
    cursor.close()

    queue = JoinableQueue()
    event = Event()

    age_ids = age_map(connection).values() + [None]
    sex_ids = sex_map(connection).values() + [None]
    education_ids = education_map(connection).values() + [None]
    province_ids = province_map(connection).values() + [None]

    cursor = connection.cursor()
    cursor.execute("SELECT DISTINCT cycle FROM core_microdata;");
    cycles = [row[0] for row in cursor]
    cursor.close()

    greenlets = []

    for i in range(50):
        gv = gevent.spawn(worker, queue, event)
        greenlets.append(gv)

    combs = itertools.product(age_ids, sex_ids, province_ids, education_ids, cycles)
    for c in combs:
        queue.put(c)

    queue.join()
    event.set()
    gevent.joinall(greenlets)
開發者ID:amaia,項目名稱:ttparo.es,代碼行數:35,代碼來源:load_ratequeries.py

示例6: __init__

 def __init__(self, *args, **kwargs):
     super(WebServer, self).__init__(*args, **kwargs)
     print 'Webserver started'
     self.debug = True
     self.cmd_queue = JoinableQueue()
     self.event_queue = JoinableQueue()
     self.cmd_id = 0
     self.cmd_results = {}
     gevent.spawn(self.send_commands_to_debugger)
     gevent.spawn(self.receive_events_from_debugger)
開發者ID:yejianye,項目名稱:webpdb,代碼行數:10,代碼來源:webserver.py

示例7: start

    def start(self):
        if not self.__threads:
            self.__threads = len(IPNetwork(self.__ip)) if len(IPNetwork(self.__ip)) <= 10 else 10
        if len(IPNetwork(self.__ip)) < int(self.__threads):
            print "Please decrease number of threads to number of hosts <= %s" % len(IPNetwork(self.__ip))
            exit()

        queue = JoinableQueue()
        [queue.put(str(ip)) for ip in IPNetwork(self.__ip)]

        workers = [spawn(self.get_ip_info, queue, self.__apis) for t in range(int(self.__threads))]

        queue.join()
開發者ID:tsma11,項目名稱:passivescan,代碼行數:13,代碼來源:passivescan.py

示例8: test_main

    def test_main(self):
        queue = JoinableQueue()
        print dir(queue)
        queue.put(1)
        queue.put(3)
        queue.put(2)
        queue.put(6)
        print queue.qsize()

        print '1', queue.get(), queue.get()
開發者ID:serg0987,項目名稱:python,代碼行數:10,代碼來源:test_gevent_queue.py

示例9: __init__

 def __init__(self, requestHandler=BaseRequestHandler(),
                    parseHandler=BaseParseHandler(),
                    sheduler=BaseScheduler(),
                    pipeline=BasePipeline()):
     self.requestHandler = requestHandler
     self.parseHandler = parseHandler
     self.sheduler = sheduler
     self.pipeline = pipeline
     self.task_queue = JoinableQueue()
     self.response_queue = JoinableQueue()
     self.tasks_cnt = 0
     self.result_queue = JoinableQueue()
     self.jobs_cnt = config.num_threads
     self.start_time = time.time()
     self.stop = False
開發者ID:atupal,項目名稱:ccrawler,代碼行數:15,代碼來源:stand_alone_run.py

示例10: __init__

    def __init__(self,url,parameter,HTTPClients,ClientConnectionPool,task=None):

        if task is not None:
            self.celeryTask = task
            self.celeryTaskId = task.request.id
        else:
            self.celeryTask = None

        self.parameter = parameter
        self.url = url
        self.numberHTTPClients = HTTPClients
        self.numberClientConnectionPool = ClientConnectionPool

        self.http = HTTPClient.from_url(URL(url),concurrency=self.numberClientConnectionPool)
        self.clientPool = gevent.pool.Pool(self.numberHTTPClients)
        self.workQueue = JoinableQueue()

        self.resultList = {}
        self.workQueueMax = 0
        self.workQueueDone = 0
        self.countRequests = 0
        self.status_codes = {}
        self.status_codes_count = {}
        self.meta = {}

        self.greenletList = {}
        self.initAdditionalStructures()
        self.progressMeta = None

        self.exitFlag = False
        self.pauseRequests = False
開發者ID:hptk,項目名稱:YouTube-Video-and-Metadata-Fetcher,代碼行數:31,代碼來源:RequestBase.py

示例11: __init__

    def __init__(self, scheme, create_devices=True,
                 write_data=True,
                 start_date="2000-01-01T00:00:00Z",
                 end_date="2014-12-31T00:00:00Z",
                 pool_size=3):
        self.scheme = scheme
        self.create_devices = create_devices
        self.should_write_data = write_data
        self.start_date = start_date
        self.end_date = end_date
        self.tdb = TDBClient(scheme.db_key, scheme.db_key,
                             scheme.db_secret,
                             base_url=scheme.db_baseurl)

        iq_endpoint = HTTPEndpoint(scheme.iq_baseurl,
                                   scheme.iq_key,
                                   scheme.iq_secret)
        self.tiq = TIQClient(iq_endpoint)
        self.queue = JoinableQueue()
        self.lock = Lock()
        self.dp_count = 0
        self.req_count = 0
        self.dp_reset = time.time()
        for i in range(pool_size):
            gevent.spawn(self.worker)
開發者ID:tempodb,項目名稱:export,代碼行數:25,代碼來源:migrate.py

示例12: __init__

 def __init__(self, creds, pool_size=POOL_SIZE):
     self.client = get_session(creds['host'],
                               creds['key'],
                               creds['secret'])
     self.queue = JoinableQueue(maxsize=POOL_SIZE*2)
     for i in range(pool_size):
         gevent.spawn(self.worker)
開發者ID:TempoIQ,項目名稱:tempoiq-tools,代碼行數:7,代碼來源:import.py

示例13: _setup_command_system

 def _setup_command_system(self):
     # we have two refs to the commands queue,
     # but write_commands_q will switch to throwaway
     # after we receive a finish command
     self._read_commands_q = JoinableQueue(None)
     self._write_commands_q = self._read_commands_q 
     for x in range(self._workers_to_start):
         gevent.spawn(self._process_commands)
開發者ID:bepetersn,項目名稱:cookcountyjail,代碼行數:8,代碼來源:concurrent_base.py

示例14: GQueue

class GQueue(object):
    def __init__(self):
        self.__QUEUE = JoinableQueue()

    def job(self, func):
        @functools.wraps(func)
        def f(*args, **kwargs):
            self.__QUEUE.put([func, args, kwargs])

        return f

    def join(self):
        self.__QUEUE.join()

    def work(self):
        while True:
            func, args, kwargs = self.__QUEUE.get()
            try:
                func(*args, **kwargs)
            finally:
                self.__QUEUE.task_done()

    def run_worker(self, num=1):
        for i in range(num):
            gevent.spawn(self.work)
開發者ID:whtsky,項目名稱:gqueue,代碼行數:25,代碼來源:gqueue.py

示例15: _run

    def _run(self):
        paths = glob.glob(self.path)
        while not paths:
            gevent.sleep(0.01)
            paths = glob.glob(self.path)
        q = JoinableQueue()

        self.logger.debug('Tailing %s' % ', '.join(paths))
        self.tails = [Tail(p, q, self.statedir) for p in paths]

        while True:
            data = q.get()
            if data:
                if data.endswith('\n'):
                    data = data[0:-1]
                self.logger.debug('Received: %r' % data)
                self.output.put(Event(data=data))
            q.task_done()
開發者ID:artirix,項目名稱:logcabin,代碼行數:18,代碼來源:file.py


注:本文中的gevent.queue.JoinableQueue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。