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 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: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105700 Hello: I=E2=80=99m trying to perform an synchronous task while using asyncio. I understand the solution is to use run_in_executor. I=E2=80=99m not clear on how to add this into an already running event loop= . I=E2=80=99ve found lots of examples showing how to set up a loop and run th= is, but I=E2=80=99m blocked in regards to doing this when the loop is already estab= lished. Example code: def blocking_func(param1): # call the blocking call here. return results async def process_request(): loop =3D asyncio.get_event_loop() block =3D loop.run_in_executor(None, blocking_func, =E2=80=9Chello=E2= =80=9D) results =3D await loop.run_until_complete(asyncio.gather(*[block, ]) The above code says =E2=80=9Cloop already running.=E2=80=9D because we=E2= =80=99re already in an async ask that has been awaited. What is the proper method of adding in this new synchronous task? Regards =E2=80=94Ray --=20 Raymond Cote, President voice: +1.603.924.6079 email: rgacote@AppropriateSolutions.com skype: ray.cote