Exemple #1
0
def launch():
	global loop
	loop = GLibEventLoop(context=GLib.MainContext.default())
	executor = ThreadPoolExecutor(max_workers=1)
	executor.submit(worker)
Exemple #2
0
def launch():
    executor = ThreadPoolExecutor(max_workers=1)
    executor.submit(worker)
Simulate a situation when multiple threads of Kafka RPC Client send request to Kafka RPC Server
"""

USE_GEVENT = True

if USE_GEVENT:
    import gevent
    as_completed = gevent.wait
    from gevent.threadpool import ThreadPoolExecutor as ThreadPoolExecutor
else:
    from concurrent.futures import ThreadPoolExecutor, as_completed

from kafka_rpc import KRPCClient

pool = ThreadPoolExecutor(128)

# assuming you kafka broker is on localhost:9092
krc = KRPCClient('localhost:9092', topic_name='sum')

# call method concurrently from client to server
# use pool.map if you like
futures = []
for i in range(128):
    futures.append(pool.submit(krc.add, 1, 2, timeout=20))

for future in as_completed(futures):
    result = future.result()
    print(result)

krc.close()
Exemple #4
0
def thread_pool_main(interface_info):
    thread_obj = ThreadPoolExecutor(max_workers=1,
                                    thread_name_prefix="WorkExecutor")
    # logger.info("Master ThreadPool Executor starts thread worker")
    thread_obj.submit(get_response(interface_info))