<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Wrapping asynchronous arcpy functions in coroutines in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/wrapping-asynchronous-arcpy-functions-in/m-p/253001#M19478</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've noticed that arcpy now has async tasks for several functions, mostly the ArcGIS Online analysis jobs. However, the docs show that the results of these jobs should blocked synchronously in scripts. Has anyone experimented with wrapping these function calls in coroutines so that they slot into&amp;nbsp;Python 3's native async pipeline? Something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import asyncio

def asCoroutine(func, args=(), kwargs={}):
&amp;nbsp;&amp;nbsp;&amp;nbsp;result = func(*args, **kwargs)
&amp;nbsp;&amp;nbsp;&amp;nbsp;return convertToFutureOrPromiseOrWhatever(result)

async def execute(paramsList):
&amp;nbsp; &amp;nbsp;results = await asyncio.gather((asCoroutine(arcpy.DoAThing_toolbox, params) for params in paramsList))
&amp;nbsp;&amp;nbsp;&amp;nbsp;for result in results: doWhatever(result)&lt;/PRE&gt;&lt;P&gt;I'm probably bungling the syntax but you get the idea. It would also be nice if the results object had a "asFuture" method in Pro 2.4 but I'll take what I can get. Any thoughts?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:15:20 GMT</pubDate>
    <dc:creator>DavidSolari</dc:creator>
    <dc:date>2021-12-12T16:15:20Z</dc:date>
    <item>
      <title>Wrapping asynchronous arcpy functions in coroutines</title>
      <link>https://community.esri.com/t5/python-questions/wrapping-asynchronous-arcpy-functions-in/m-p/253001#M19478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've noticed that arcpy now has async tasks for several functions, mostly the ArcGIS Online analysis jobs. However, the docs show that the results of these jobs should blocked synchronously in scripts. Has anyone experimented with wrapping these function calls in coroutines so that they slot into&amp;nbsp;Python 3's native async pipeline? Something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import asyncio

def asCoroutine(func, args=(), kwargs={}):
&amp;nbsp;&amp;nbsp;&amp;nbsp;result = func(*args, **kwargs)
&amp;nbsp;&amp;nbsp;&amp;nbsp;return convertToFutureOrPromiseOrWhatever(result)

async def execute(paramsList):
&amp;nbsp; &amp;nbsp;results = await asyncio.gather((asCoroutine(arcpy.DoAThing_toolbox, params) for params in paramsList))
&amp;nbsp;&amp;nbsp;&amp;nbsp;for result in results: doWhatever(result)&lt;/PRE&gt;&lt;P&gt;I'm probably bungling the syntax but you get the idea. It would also be nice if the results object had a "asFuture" method in Pro 2.4 but I'll take what I can get. Any thoughts?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:15:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/wrapping-asynchronous-arcpy-functions-in/m-p/253001#M19478</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2021-12-12T16:15:20Z</dc:date>
    </item>
  </channel>
</rss>

