Adding run_in_executor task to already existing loop.
Ray Cote
rgacote at appropriatesolutions.com
Fri Mar 25 16:24:13 EDT 2016
Hello:
I’m trying to perform an synchronous task while using asyncio.
I understand the solution is to use run_in_executor.
I’m not clear on how to add this into an already running event loop.
I’ve found lots of examples showing how to set up a loop and run this, but
I’m blocked in regards to doing this when the loop is already established.
Example code:
def blocking_func(param1):
# call the blocking call here.
return results
async def process_request():
loop = asyncio.get_event_loop()
block = loop.run_in_executor(None, blocking_func, “hello”)
results = await loop.run_until_complete(asyncio.gather(*[block, ])
The above code says “loop already running.” because we’re already in an
async ask that has been awaited. What is the proper method of adding in
this new synchronous task?
Regards
—Ray
--
Raymond Cote, President
voice: +1.603.924.6079 email: rgacote at AppropriateSolutions.com skype:
ray.cote
More information about the Python-list
mailing list