AnsweredAssumed Answered

Wrapping asynchronous arcpy functions in coroutines

Question asked by LTS_DSolari on Apr 18, 2019

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 Python 3's native async pipeline? Something like:

import asyncio

def asCoroutine(func, args=(), kwargs={}):
   result = func(*args, **kwargs)
   return convertToFutureOrPromiseOrWhatever(result)

async def execute(paramsList):
   results = await asyncio.gather((asCoroutine(arcpy.DoAThing_toolbox, params) for params in paramsList))
   for result in results: doWhatever(result)

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?

Outcomes