Select to view content in your preferred language

Wrapping asynchronous arcpy functions in coroutines

1005
0
04-18-2019 12:05 PM
DavidSolari
Frequent Contributor

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?

0 Kudos
0 Replies