Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105700

Adding run_in_executor task to already existing loop.

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.freenet.ag!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Ray Cote <rgacote@appropriatesolutions.com>
Newsgroups comp.lang.python
Subject Adding run_in_executor task to already existing loop.
Date Fri, 25 Mar 2016 16:24:13 -0400
Lines 36
Message-ID <mailman.7.1458937485.28225.python-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de eUuSiobpsfmLoYtYMv87qQyDKkxlfEiNmR0IlHZOrVkA==
Return-Path <rgacote@appropriatesolutions.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.032
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'blocked': 0.09; 'i\xe2\x80\x99ve': 0.09; 'loop.': 0.09; 'def': 0.13; 'async': 0.16; 'hello:': 0.16; 'i\xe2\x80\x99m': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Adding': 0.16; 'subject:already': 0.16; 'skip:= 20': 0.22; 'trying': 0.22; 'skip:l 40': 0.23; 'examples': 0.24; 'example': 0.26; 'message- id:@mail.gmail.com': 0.27; 'blocking': 0.29; 'code:': 0.29; 'code': 0.30; 'raymond': 0.30; 'task': 0.30; 'says': 0.32; 'run': 0.33; 'running': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'clear': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'method': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'received:209': 0.38; 'skype:': 0.38; 'skip:p 20': 0.38; 'to:addr:python.org': 0.40; 'email:': 0.62; 'here.': 0.62; 'results': 0.66; 'skip:\xe2 10': 0.70; '8bit%:57': 0.72; 'await': 0.76; 'we\xe2\x80\x99re': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=appropriatesolutions.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=DDR+JcvBm27DlXfUOzoEBkXdBGU4nfLI0vImRlQhCIs=; b=ddgl/m8leWdhGo8Do/TIlRMdm/bU2HFDYv9YYxYGIqU4cLu1SUQpVIdZZBbbksYmIV Sx9mrdRef3YI4A+nPWM1ANjWjFrvMrodZ0NvPLlX5Ein65qWm4BMCkwcAai2n3lrybrq AdWIrNPAJpGBU7ZZJ0VcgUzUSw0V+hUe3HIto=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=DDR+JcvBm27DlXfUOzoEBkXdBGU4nfLI0vImRlQhCIs=; b=EAx9vRAJ8qNleY4G4boCiPBWQIYVA1cR4K1HH5gHs2lGqtANBQvXrwHGVWzRIiFewi ZgXcrHlmp30bs0QhJTbizEYylkAFt5KVOY9CK2zV8YPJdFxgZZeXswI7ay2C28JIWLvh kBhufd2eTnmPaI/Em8T2PuTMApVZMjagVpGF8uPCsvLpy3nQaQq2zqrJxXuyat+Evq/h zXNgOqa+4+RD9UQBS7m4kob5Hd8vkpChWOExKBXgZ3i6k7CXkYVaYrxC4TbFxlsTES0s q+f3puW3h+RL0wkbU/TbxcA2l136xr5UQrQs5hXUBWl6RuJFS2UVsl6bwEKNJHKt0zIa rrRQ==
X-Gm-Message-State AD7BkJKrbfcsRhoW0OIPBKhRiulDg4y5hYIrAJJaOXrj2mssrBkdgVZYujd5UEwHRa74AH5Ik6VDAFL7+Zds7Q==
X-Received by 10.31.33.84 with SMTP id h81mr8489230vkh.24.1458937482380; Fri, 25 Mar 2016 13:24:42 -0700 (PDT)
X-Content-Filtered-By Mailman/MimeDel 2.1.21
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:105700

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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