Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105700
| From | Ray Cote <rgacote@appropriatesolutions.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Adding run_in_executor task to already existing loop. |
| Date | 2016-03-25 16:24 -0400 |
| Message-ID | <mailman.7.1458937485.28225.python-list@python.org> (permalink) |
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@AppropriateSolutions.com skype:
ray.cote
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Adding run_in_executor task to already existing loop. Ray Cote <rgacote@appropriatesolutions.com> - 2016-03-25 16:24 -0400
Re: Adding run_in_executor task to already existing loop. Marko Rauhamaa <marko@pacujo.net> - 2016-03-25 22:56 +0200
Re: Adding run_in_executor task to already existing loop. Zachary Ware <zachary.ware+pylist@gmail.com> - 2016-03-25 16:00 -0500
csiph-web