<?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 Is there an example for how to use the returned Future object? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/is-there-an-example-for-how-to-use-the-returned/m-p/819908#M2754</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In ArcGIS Python API 1.8.1, it allows you to make an asynchronous call of delete_features function by setting the future parameter to True.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The API document is here:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features" title="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features"&gt;arcgis.features module — arcgis 1.8.2 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Returns:&amp;nbsp; Dict if future=False (default), else a concurrent.Future class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to check the Future.result() to see if the operation has completed or failed. (there are nearly 1 million records...) :&amp;nbsp;&amp;nbsp;my understanding is it should only return when it is completed or it is failed, but actually it returns the following dictionary:&lt;/P&gt;&lt;PRE style="color: #000000; background-color: #ffffff; border: 0px; font-size: 14px; padding: 1px 0px;"&gt;{'submissionTime': 1604031554270, 'lastUpdatedTime': 1604031554270, 'status': 'Pending'}&lt;/PRE&gt;&lt;P&gt;So, what's the use of returning a Future object which seems returned immediately and never gets updated? is there an example to show how I am supposed to use this return?&amp;nbsp; I'll ask the same question for &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.Table.calculate"&gt;calculate &lt;/A&gt;function .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I alone in this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Nov 2020 05:49:16 GMT</pubDate>
    <dc:creator>simoxu</dc:creator>
    <dc:date>2020-11-02T05:49:16Z</dc:date>
    <item>
      <title>Is there an example for how to use the returned Future object?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/is-there-an-example-for-how-to-use-the-returned/m-p/819908#M2754</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In ArcGIS Python API 1.8.1, it allows you to make an asynchronous call of delete_features function by setting the future parameter to True.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The API document is here:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features" title="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features"&gt;arcgis.features module — arcgis 1.8.2 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Returns:&amp;nbsp; Dict if future=False (default), else a concurrent.Future class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to check the Future.result() to see if the operation has completed or failed. (there are nearly 1 million records...) :&amp;nbsp;&amp;nbsp;my understanding is it should only return when it is completed or it is failed, but actually it returns the following dictionary:&lt;/P&gt;&lt;PRE style="color: #000000; background-color: #ffffff; border: 0px; font-size: 14px; padding: 1px 0px;"&gt;{'submissionTime': 1604031554270, 'lastUpdatedTime': 1604031554270, 'status': 'Pending'}&lt;/PRE&gt;&lt;P&gt;So, what's the use of returning a Future object which seems returned immediately and never gets updated? is there an example to show how I am supposed to use this return?&amp;nbsp; I'll ask the same question for &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.Table.calculate"&gt;calculate &lt;/A&gt;function .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I alone in this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 05:49:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/is-there-an-example-for-how-to-use-the-returned/m-p/819908#M2754</guid>
      <dc:creator>simoxu</dc:creator>
      <dc:date>2020-11-02T05:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Is there an example for how to use the returned Future object?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/is-there-an-example-for-how-to-use-the-returned/m-p/1221301#M7884</link>
      <description>&lt;P&gt;Hello from the future.&amp;nbsp; You are not alone, I was curious as well, and I haven't been able to find any examples online.&lt;/P&gt;&lt;P&gt;I took a look at the source code of layer.py (defines arcgis.features.FeatureLayer objects, you might find it in&amp;nbsp;"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features").&amp;nbsp; Let's take the delete_features() method as an example, line 2532 (at least in the current version) looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        if future is False:
            return self._con.post(path=delete_url, postdata=params)
        else:
            params["async"] = True
            import concurrent.futures

            executor = concurrent.futures.ThreadPoolExecutor(1)
            res = self._con.post(path=delete_url, postdata=params)
            time.sleep(2)
            future = executor.submit(
                self._status_via_url,
                *(self._con, res["statusUrl"], {"f": "json"}),
            )
            executor.shutdown(False)

            return future&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;So, indeed we're getting back a conccurent.futures.Future object.&amp;nbsp; We could then use the concurrent.futures.as_completed() function to iterate over a list of Future objects' results as they finish up.&lt;/P&gt;&lt;P&gt;The following snippet shows how you could send off a few different operations on FeatureLayer objects and summarize the results as they come in:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
from concurrent.futures import as_completed

username = ""
password = ""
gis = arcgis.gis.GIS("https://arcgis.com", username, password)

f_lyr_urls = [
    "https://services6.arcgis.com/blahblahblah/1",
    "https://services6.arcgis.com/blahblahblah/2",
    "https://services6.arcgis.com/blahblahblah/3"
]

futures = []
for url in f_lyr_urls:
    f_lyr = arcgis.features.FeatureLayer(url, gis)
    future = f_lyr.delete_features(where="1=1", future=True)
    futures.append(future)

for future in as_completed(futures):
    result_dict = future.result()

    layer_name = result_dict.get("layerName")
    status = result_dict.get("status")
    n_deletes = result_dict.get("recordCount")

    message = f"{layer_name}: {status}"
    if n_deletes:
        message += f": {n_deletes} records deleted"

    print(message)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not claim that this is a&amp;nbsp;&lt;EM&gt;good&lt;/EM&gt; example, however, because I'm pretty sure the way this works is that each call to delete_features() spins up its own ThreadPoolExecutor, but if I understand the documentation correctly (it says "All threads enqueued to ThreadPoolExecutor will be joined before the interpreter can exit") then each thread pool is blocking the rest of the program until it finishes.&lt;/P&gt;&lt;P&gt;So, no matter what using future=True is going to be slower than just running it synchronously, since each thread pool only sends one request and is going to block everything else anyway, so you might as well not create the new thread.&lt;/P&gt;&lt;P&gt;Unless I'm misunderstanding something, this is a completely useless implementation by ESRI.&amp;nbsp; They should instead return to us all the junk they're passing to executor.submit() so that we can lump together all the POST requests we want to send into the same thread pool.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 22:20:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/is-there-an-example-for-how-to-use-the-returned/m-p/1221301#M7884</guid>
      <dc:creator>SamSzotkowski</dc:creator>
      <dc:date>2022-10-12T22:20:13Z</dc:date>
    </item>
  </channel>
</rss>

