本文整理汇总了Python中gevent.queue方法的典型用法代码示例。如果您正苦于以下问题:Python gevent.queue方法的具体用法?Python gevent.queue怎么用?Python gevent.queue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent
的用法示例。
在下文中一共展示了gevent.queue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_channel
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def make_channel(self):
"""Returns a single-slot communication device for passing data and control
between concurrent functions.
This is useful for running 'background helper' type concurrent processes.
NOTE: It is strongly discouraged to pass Channel objects outside of a recipe
module. Access to the channel should be mediated via
a class/contextmanager/function which you return to the caller, and the
caller can call in a makes-sense-for-your-moudle's-API way.
See ./tests/background_helper.py for an example of how to use a Channel
correctly.
It is VERY RARE to need to use a Channel. You should avoid using this unless
you carefully consider and avoid the possibility of introducing deadlocks.
Channels will raise ValueError if used with @@@annotation@@@ mode.
"""
if not self.concurrency_client.supports_concurrency: # pragma: no cover
# test mode always supports concurrency, hence the nocover
raise ValueError('Channels are not allowed in @@@annotation@@@ mode')
return gevent.queue.Channel()
示例2: usecase_child_d
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def usecase_child_d(forthreader, backwriter):
recvqueue = gevent.queue.Queue()
def g_from_forthpipe_to_q(forthreader):
while True:
m = forthreader.get()
recvqueue.put(m)
if m == "STOP":
break
def g_from_q_to_backpipe(backwriter):
while True:
m = recvqueue.get()
backwriter.put(m)
if m == "STOP":
break
g1 = gevent.spawn(g_from_forthpipe_to_q, forthreader)
g2 = gevent.spawn(g_from_q_to_backpipe, backwriter)
g1.get()
g2.get()
示例3: __init__
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def __init__(self, device, prefix, watermark, attributes, persistent):
super(DevicePusher, self).__init__()
self.device = device
self.xapi = pan.xapi.PanXapi(
tag=self.device.get('tag', None),
api_username=self.device.get('api_username', None),
api_password=self.device.get('api_password', None),
api_key=self.device.get('api_key', None),
port=self.device.get('port', None),
hostname=self.device.get('hostname', None),
serial=self.device.get('serial', None)
)
self.valid_device_version = None
self.prefix = prefix
self.attributes = attributes
self.watermark = watermark
self.persistent = persistent
self.q = gevent.queue.Queue()
示例4: __init__
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def __init__(self, device, prefix, watermark, attributes, persistent):
super(DevicePusher, self).__init__()
self.device = device
self.xapi = pan.xapi.PanXapi(
tag=self.device.get('tag', None),
api_username=self.device.get('api_username', None),
api_password=self.device.get('api_password', None),
api_key=self.device.get('api_key', None),
port=self.device.get('port', None),
hostname=self.device.get('hostname', None),
serial=self.device.get('serial', None)
)
self.prefix = prefix
self.attributes = attributes
self.watermark = watermark
self.persistent = persistent
self.q = gevent.queue.Queue()
示例5: __init__
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def __init__(self, name, chassis, config):
self.table = None
self.agg_table = None
self._actor_queue = gevent.queue.Queue(maxsize=128)
self._actor_glet = None
self._actor_commands_ts = collections.defaultdict(int)
self._poll_glet = None
self._age_out_glet = None
self._emit_counter = 0
self.last_run = None
self.last_successful_run = None
self.last_ageout_run = None
self._sub_state = None
self._sub_state_message = None
self.poll_event = gevent.event.Event()
self.state_lock = RWLock()
super(BasePollerFT, self).__init__(name, chassis, config)
示例6: __init__
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def __init__(self, id, parser, driver, cpu=None, is_process=True):
self.parser = parser
self.driver = driver
self.id = id
self._running = False
self._rpc_task = None
self._events_task = None
self._health_task = None
self.queue = gevent.queue.Queue(maxsize=10000)
self.cpu = cpu
self.is_process = is_process
self.logger = init_logging("main.{}".format(self.id))
self.error_mr = MetricsRecorder("sniffer.main.error")
self.msg_mr = MetricsRecorder("sniffer.main.msg")
self.event_mr = MetricsRecorder("sniffer.main.event")
self.rpc_mr = MetricsRecorder("sniffer.main.rpc")
self.main_mr = MetricsRecorder("sniffer.main.loop")
self.urltree = URLTree()
示例7: __init__
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def __init__(self, app):
log.debug('initializing JSONRPCServer')
BaseService.__init__(self, app)
self.app = app
self.dispatcher = LoggingDispatcher()
# register sub dispatchers
for subdispatcher in self.subdispatcher_classes():
subdispatcher.register(self)
transport = WsgiServerTransport(queue_class=gevent.queue.Queue)
# start wsgi server as a background-greenlet
self.listen_port = app.config['jsonrpc']['listen_port']
self.listen_host = app.config['jsonrpc']['listen_host']
self.wsgi_server = gevent.wsgi.WSGIServer((self.listen_host, self.listen_port),
transport.handle, log=WSGIServerLogger)
self.rpc_server = RPCServerGreenlets(
transport,
JSONRPCProtocol(),
self.dispatcher
)
self.default_block = 'latest'
示例8: manage
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def manage(self):
""""
Manage will hand out work when the appropriate Worker is free.
The manager timeout must be less than worker timeout, or else, the
workers will be idled and shutdown.
"""
try:
while True:
for name, workgroup in self.workgroups.items():
for qname, q in self.qitems.items():
if name == qname: # workgroup name must match tracker name
# a tracker with the same name as workgroup name, is...
# ...effectively, the workgroup's task queue, so now...
# assign a task to a worker from the workgroup's task queue
for worker in workgroup:
one_task = q.get(timeout=self.mgr_qtimeout)
worker.tasks.put(one_task)
gevent.sleep(0)
except Empty:
self.mgr_no_work = True
if self.mgr_should_stop:
logger.info(f"Assigned all {name} work. I've been told I should stop.")
self.should_stop = True
else:
logger.info(f"Assigned all {name} work. Awaiting more tasks to assign.")
示例9: fetch_urls
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def fetch_urls(self, queue, quantity):
while not queue.empty():
url = queue.get()
html = self.s.get(url, headers=self.headers).text
pq = PyQuery(html)
size = pq.find('tbody tr').size()
for index in range(size):
item = pq.find('tbody tr').eq(index)
ip = item.find('td').eq(0).text()
port = item.find('td').eq(1).text()
_type = item.find('td').eq(3).text()
self.result_arr.append({
str(_type).lower(): '{0}://{1}:{2}'.format(str(_type).lower(), ip, port)
})
if len(self.result_arr) >= quantity:
break
示例10: _SendLoop
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def _SendLoop(self):
"""Dispatch messages from the send queue to the remote server.
Note: Messages in the queue have already been serialized into wire format.
"""
while self.isActive:
try:
payload, dct = self._send_queue.get()
queue_len = self._send_queue.qsize()
self._varz.send_queue_size(queue_len)
# HandleTimeout sets up the transport level timeout handling
# for this message. If the message times out in transit, this
# transport will handle sending a Tdiscarded to the server.
if self._HandleTimeout(dct): continue
with self._varz.send_time.Measure():
with self._varz.send_latency.Measure():
self._socket.write(payload)
self._varz.messages_sent()
except Exception as e:
self._Shutdown(e)
break
示例11: _concurrent_execute
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def _concurrent_execute(self, context, start_req, parser, pool, pool_size):
queue = Queue() # 任务队列
# 将初始化请求加入任务队列
for r in start_req:
queue.put_nowait(r)
if pool is None:
pool = GeventPool(pool_size)
greenlets = []
while True:
try:
req = self._check_req(queue.get(timeout=1))
if req.parser is None:
req.parser = parser
greenlets.append(pool.spawn(req, context, queue))
except Empty:
break
return [greenlet.get() for greenlet in greenlets]
示例12: test_create_config
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def test_create_config(zk, test_application_name, long_poll):
queue = long_poll()
event = queue.get(timeout=5)
assert event['message'] == 'all'
assert event['body'] == {
'service': {test_application_name: {'stable': {}, 'foo': {}}},
'switch': {test_application_name: {'stable': {}}},
'config': {test_application_name: {}},
'service_info': {},
}
assert queue.empty()
zk.create(
'/huskar/config/%s/alpha/DB_URL' % test_application_name, 'mysql://',
makepath=True)
event = queue.get(timeout=5)
assert event['message'] == 'update'
assert event['body'] == {'config': {
test_application_name: {'alpha': {'DB_URL': {u'value': u'mysql://'}}},
}}
示例13: test_delete_config
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def test_delete_config(zk, test_application_name, long_poll):
zk.create(
'/huskar/config/%s/alpha/DB_URL' % test_application_name, 'mysql://',
makepath=True)
queue = long_poll()
event = queue.get(timeout=5)
assert event['message'] == 'all'
assert event['body'] == {
'service': {test_application_name: {'stable': {}, 'foo': {}}},
'switch': {test_application_name: {'stable': {}}},
'config': {
test_application_name: {'alpha': {
'DB_URL': {u'value': u'mysql://'},
}},
},
'service_info': {}
}
zk.delete('/huskar/config/%s/alpha/DB_URL' % test_application_name)
event = queue.get(timeout=5)
assert event['message'] == 'delete'
assert event['body'] == {'config': {
test_application_name: {'alpha': {'DB_URL': {u'value': None}}}
}}
示例14: test_tree_broadcast
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def test_tree_broadcast(zk, long_poll, test_application_name):
zk.create('/huskar/config/%s/alpha/foo' % test_application_name, 'FOO',
makepath=True)
queue_a = long_poll()
queue_b = long_poll()
for queue in queue_a, queue_b:
event = queue.get(timeout=5)
assert event['message'] == 'all'
assert event['body']['config'] == {
test_application_name: {'alpha': {'foo': {'value': 'FOO'}}},
}
assert queue.empty()
zk.create('/huskar/config/%s/alpha/bar' % test_application_name, 'BAR',
makepath=True)
for queue in queue_a, queue_b:
event = queue.get(timeout=5)
assert event['message'] == 'update'
assert event['body']['config'] == {
test_application_name: {'alpha': {'bar': {'value': 'BAR'}}},
}
assert queue.empty()
示例15: test_jira_845_regression_1
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import queue [as 别名]
def test_jira_845_regression_1(zk, test_application_name, long_poll):
"""Fix http://jira.ele.to:8088/browse/FXBUG-845."""
zk.create(
'/huskar/service/%s/foo/169.254.0.1_5000' % test_application_name,
'{"ip":"169.254.0.1","port":{"main":5000}}', makepath=True)
queue = long_poll()
event = queue.get(timeout=5)
assert event['message'] == 'all'
zk.create('/huskar/service/%s/beta' % test_application_name,
'{"link":["foo"]}', makepath=True)
zk.create(
'/huskar/service/%s/foo/169.254.0.2_5000' % test_application_name,
'', makepath=True)
event = queue.get(timeout=5)
assert event['message'] != 'all', 'We should be silent for cluster linking'
assert queue.empty(), 'We should notify for node creation only'