当前位置: 首页>>代码示例>>Python>>正文


Python Queue.get_nowait方法代码示例

本文整理汇总了Python中eventlet.Queue.get_nowait方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.get_nowait方法的具体用法?Python Queue.get_nowait怎么用?Python Queue.get_nowait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eventlet.Queue的用法示例。


在下文中一共展示了Queue.get_nowait方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connection_pooling

# 需要导入模块: from eventlet import Queue [as 别名]
# 或者: from eventlet.Queue import get_nowait [as 别名]
    def test_connection_pooling(self):
        with patch('swift.common.memcached.socket') as mock_module:
            # patch socket, stub socket.socket, mock sock
            mock_sock = mock_module.socket.return_value

            # track clients waiting for connections
            connected = []
            connections = Queue()
            errors = []

            def wait_connect(addr):
                connected.append(addr)
                sleep(0.1)  # yield
                val = connections.get()
                if val is not None:
                    errors.append(val)

            mock_sock.connect = wait_connect

            memcache_client = memcached.MemcacheRing(['1.2.3.4:11211'],
                                                     connect_timeout=10)
            # sanity
            self.assertEquals(1, len(memcache_client._client_cache))
            for server, pool in memcache_client._client_cache.items():
                self.assertEqual(2, pool.max_size)

            # make 10 requests "at the same time"
            p = GreenPool()
            for i in range(10):
                p.spawn(memcache_client.set, 'key', 'value')
            for i in range(3):
                sleep(0.1)
                self.assertEqual(2, len(connected))

            # give out a connection
            connections.put(None)

            # at this point, only one connection should have actually been
            # created, the other is in the creation step, and the rest of the
            # clients are not attempting to connect. we let this play out a
            # bit to verify.
            for i in range(3):
                sleep(0.1)
                self.assertEqual(2, len(connected))

            # finish up, this allows the final connection to be created, so
            # that all the other clients can use the two existing connections
            # and no others will be created.
            connections.put(None)
            connections.put('nono')
            self.assertEqual(2, len(connected))
            p.waitall()
            self.assertEqual(2, len(connected))
            self.assertEqual(0, len(errors),
                             "A client was allowed a third connection")
            connections.get_nowait()
            self.assertTrue(connections.empty())
开发者ID:vbaret,项目名称:swift,代码行数:59,代码来源:test_memcached.py

示例2: card_generate

# 需要导入模块: from eventlet import Queue [as 别名]
# 或者: from eventlet.Queue import get_nowait [as 别名]
def card_generate():
    # Filebased systems need the session cleaned up manually
    session_manager.cleanup_sessions()
    checkpoint_option = session['checkpoint_path']
    do_nn = checkpoint_option != "None"
    if do_nn:
        checkpoint_path = os.path.join(
            os.path.expanduser(app.config['SNAPSHOTS_PATH']),
            checkpoint_option)
    length = int(session['length'])
    if length > app.config['LENGTH_LIMIT']:
        length = app.config['LENGTH_LIMIT']
    socketio.emit('set max char', {'data': length})
    length += 140  # Small fudge factor to be a little more accurate with
    # the amount of text actually generated
    use_render_mode(session["render_mode"])
    if do_nn:
        command = ['th', 'sample_hs_v3.1.lua', checkpoint_path, '-gpuid',
                   str(app.config['GPU'])]
    else:
        command = ['-gpuid', str(app.config['GPU'])]
    if session['seed']:
        command += ['-seed', str(session['seed'])]
    if session['primetext']:
        command += ['-primetext', session['primetext']]
    if session['length']:
        command += ['-length', str(length)]
    if session['temperature']:
        command += ['-temperature', str(session['temperature'])]
    if session['name']:
        command += ['-name', session['name']]
    if session['types']:
        command += ['-types', session['types']]
    if session['supertypes']:
        command += ['-supertypes', session['supertypes']]
    if session['subtypes']:
        command += ['-subtypes', session['subtypes']]
    if session['rarity']:
        command += ['-rarity', session['rarity']]
    if session['bodytext_prepend']:
        command += ['-bodytext_prepend', session['bodytext_prepend']]
    if session['bodytext_append']:
        command += ['-bodytext_append', session['bodytext_append']]
    if do_nn:
        room = session['csrf_token']
        join_room(room)
        session['mode'] = "nn"
        session['cardtext'] = ''
        app.logger.debug("Card generation initiated: " + ' '.join(command))
        pipe = PIPE
        with Popen(command,
                   cwd=os.path.expanduser(
                       app.config['GENERATOR_PATH']),
                   shell=False,
                   stdout=pipe) as process:
            queue = Queue()
            thread = eventlet.spawn(enqueue_output, process, queue)
            while process.poll() is None:
                try:
                    time.sleep(0.01)
                    line = queue.get_nowait()
                except Empty:
                    pass
                else:
                    socketio.emit('raw card', {'data': line}, room=room)
                    if session["do_text"]:
                        card = convert_to_card(line)
                        if card:
                            socketio.emit('text card', {
                                'data': card.format().replace('@',
                                                              card.name.title()).split(
                                    '\n')},
                                          room=room)
                    if session["do_images"]:
                        socketio.emit('image card', {
                            'data': urllib.parse.quote(line, safe='') +
                                    session[
                                        "image_extra_params"]},
                                      room=room)
                    session[
                        'cardtext'] += line + '\n'  # Recreate the output from the sampler
                    app.logger.debug("Card generated: " + line.rstrip('\n\n'))

        session['cardsep'] = '\n\n'
        app.logger.debug("Card generation complete.")
    else:
        session['mode'] = "dummy"
        session['command'] = " ".join(command)
    session.modified = True
    app.save_session(session, make_response('dummy'))
    socketio.emit('finished generation', {'data': ''}, room=room)
    leave_room(room)
开发者ID:croxis,项目名称:mtgai,代码行数:94,代码来源:views.py


注:本文中的eventlet.Queue.get_nowait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。