<?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 Re: How to use arcpy.env with multithreading? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1261948#M65975</link>
    <description>&lt;P&gt;Sorry for my late reaction/response.&lt;/P&gt;&lt;P&gt;I have some trouble with the python environment in ArcGIS Pro.&lt;BR /&gt;How to "Run stand-alone scripts" is documeted here:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/using-conda-with-arcgis-pro.htm" target="_blank"&gt;Run stand-alone scripts—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I check the arcpy.env in the Python window of ArcGIS Pro with len(arcpy.env.keys())&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has 68 attributes&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;I open the ArcGIS Python environment via Windows and check arcpy.env&lt;BR /&gt;c:\Progra~1\ArcGIS\Pro\bin\Python\scripts\propy.bat&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has 68 attributes - okay&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;I open a subprocess from the Python window of ArcGIS Pro and check arcpy.env in the new subprocess&lt;BR /&gt;&lt;EM&gt;import suprocess &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sp = subprocess.Popen([r'c:\Progra~1\ArcGIS\Pro\bin\Python\scripts\propy.bat'])&lt;/EM&gt;&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has 68 attributes - okay&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;I open a subprocess via a toolbox script of ArcGIS Pro and check arcpy.env in the new subprocess.&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has only 9 attributes - why?&lt;/STRONG&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.keys()&lt;BR /&gt;['scratchGDB', 'scratchFolder', 'packageWorkspace', 'scriptWorkspace', 'addOutputsToMap', 'buildStatsAndRATForTempRaster', 'autoCancelling', 'isCancelled', 'overwriteOutput']&lt;BR /&gt;&lt;BR /&gt;get and set the other attributes causes an exception&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.compression&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;AttributeError: 'GPEnvironment' object has no attribute 'compression'&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.compression = 'PackBits'&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;AttributeError: 'GPEnvironment' object has no attribute 'compression'&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I need arcpy.env attributes&amp;nbsp; 'compression', 'pyramid' and 'rasterStatisticsfor'&amp;nbsp; to &lt;SPAN&gt;merge and clip (with arcpy.management.clip()) thousands of tiles in a second/parallel process.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Does somebody has any idea?&lt;/P&gt;</description>
    <pubDate>Mon, 27 Feb 2023 11:34:35 GMT</pubDate>
    <dc:creator>JörgEbert</dc:creator>
    <dc:date>2023-02-27T11:34:35Z</dc:date>
    <item>
      <title>How to use arcpy.env with multithreading?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1256947#M65354</link>
      <description>&lt;P&gt;I have a tool to automate map export to TIFF for thousands of tiles.&lt;BR /&gt;The active view (ArcGIS Pro 3.0.3) is exported to three (or more) TIFFs for evry tile in the main thread and in a second thread the TIFFs of a tile are merged and clipped with arcpy.management.clip().&lt;BR /&gt;My tool works fine.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But is it possible to clip TIFFs in a secondray thread to TIFFs with custom compression type "JPEG", "PackBits" or "NONE"?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The arcpy.management.clip() tool uses arcpy.env.compression as the compression type of the output raster. (Default LZW for TIFF).&lt;BR /&gt;Setting arcpy.env.compression in the secondary thread throws an exception "AttributeError: ERROR 87934" - I think arcpy.env from the main thread cannot be used in a secondary thread.&lt;BR /&gt;The arcpy.management.clip() tool in Secondary does not accept arcpy.env from the main thread. It seems that the tool works with the standard arcpy.env/without any settings.&lt;/P&gt;&lt;P&gt;Does anyone have any ideas (other than working with subprocesses)?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 12:30:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1256947#M65354</guid>
      <dc:creator>JörgEbert</dc:creator>
      <dc:date>2023-02-10T12:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arcpy.env with multithreading?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1256979#M65359</link>
      <description>&lt;P&gt;from &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/attributeerror-error-87934-replication-and/td-p/1134705" target="_blank" rel="noopener"&gt;AttributeError: ERROR 87934 replication and multit... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/threading-vs-multiprocessing-for-concurrent-gp/m-p/582360#M45653" target="_blank"&gt;Solved: threading vs multiprocessing for concurrent gp too... - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 13:53:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1256979#M65359</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-02-10T13:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arcpy.env with multithreading?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1261948#M65975</link>
      <description>&lt;P&gt;Sorry for my late reaction/response.&lt;/P&gt;&lt;P&gt;I have some trouble with the python environment in ArcGIS Pro.&lt;BR /&gt;How to "Run stand-alone scripts" is documeted here:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/using-conda-with-arcgis-pro.htm" target="_blank"&gt;Run stand-alone scripts—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I check the arcpy.env in the Python window of ArcGIS Pro with len(arcpy.env.keys())&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has 68 attributes&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;I open the ArcGIS Python environment via Windows and check arcpy.env&lt;BR /&gt;c:\Progra~1\ArcGIS\Pro\bin\Python\scripts\propy.bat&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has 68 attributes - okay&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;I open a subprocess from the Python window of ArcGIS Pro and check arcpy.env in the new subprocess&lt;BR /&gt;&lt;EM&gt;import suprocess &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sp = subprocess.Popen([r'c:\Progra~1\ArcGIS\Pro\bin\Python\scripts\propy.bat'])&lt;/EM&gt;&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has 68 attributes - okay&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;I open a subprocess via a toolbox script of ArcGIS Pro and check arcpy.env in the new subprocess.&lt;BR /&gt;&lt;STRONG&gt;arcpy.env has only 9 attributes - why?&lt;/STRONG&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.keys()&lt;BR /&gt;['scratchGDB', 'scratchFolder', 'packageWorkspace', 'scriptWorkspace', 'addOutputsToMap', 'buildStatsAndRATForTempRaster', 'autoCancelling', 'isCancelled', 'overwriteOutput']&lt;BR /&gt;&lt;BR /&gt;get and set the other attributes causes an exception&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.compression&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;AttributeError: 'GPEnvironment' object has no attribute 'compression'&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.compression = 'PackBits'&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;AttributeError: 'GPEnvironment' object has no attribute 'compression'&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I need arcpy.env attributes&amp;nbsp; 'compression', 'pyramid' and 'rasterStatisticsfor'&amp;nbsp; to &lt;SPAN&gt;merge and clip (with arcpy.management.clip()) thousands of tiles in a second/parallel process.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Does somebody has any idea?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 11:34:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1261948#M65975</guid>
      <dc:creator>JörgEbert</dc:creator>
      <dc:date>2023-02-27T11:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arcpy.env with multithreading?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1262610#M66033</link>
      <description>&lt;P&gt;Can you share information about how you're calling the subprocess in your last case? It sounds like this might be something best handled through support to get enough details to understand the nature of the problem, it may be a bug, but also may be some more complicated configuration is required.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 17:53:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1262610#M66033</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2023-02-28T17:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arcpy.env with multithreading?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1262935#M66068</link>
      <description>&lt;P&gt;I created a simple tool (without parameters).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JrgEbert_0-1677658936475.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/64001i2EC9FCDA36CAC4BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JrgEbert_0-1677658936475.png" alt="JrgEbert_0-1677658936475.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Running the tool will launch the Python console, just like above from the ArcGIS Pro Python window.&lt;BR /&gt;In the Python console I check arcpy.env&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JrgEbert_1-1677659203293.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/64002iC617D8340A699BE4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JrgEbert_1-1677659203293.png" alt="JrgEbert_1-1677659203293.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you for your efforts&lt;/P&gt;&lt;P&gt;And yes, I also sent this issue to Esri Support yesterday.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 08:38:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1262935#M66068</guid>
      <dc:creator>JörgEbert</dc:creator>
      <dc:date>2023-03-01T08:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arcpy.env with multithreading?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1263323#M66105</link>
      <description>&lt;P&gt;OK, I took a look at this. It looks like the subprocess call is copying the full environment variable table that Pro is using, and that is causing ArcPy to be run as if it were in the application which subsequently fails to load some components of the software (including the ones which include your env properties).&lt;BR /&gt;&lt;BR /&gt;Running this should let you work around this limitation:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
import subprocess

cmd_env = os.environ.copy()
if 'GP_PROXY_OPS' in cmd_env.keys():
    cmd_env.pop('GP_PROXY_OPS')
subprocess.run([r"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat"], env=cmd_env)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Once that is set, &amp;nbsp;the rest of ArcPy should load and you should see the expected full env dictionary.&lt;BR /&gt;&lt;BR /&gt;Cheers, Shaun&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 22:44:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1263323#M66105</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2023-03-01T22:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arcpy.env with multithreading?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1263439#M66118</link>
      <description>&lt;P&gt;Great, it works perfectly&lt;BR /&gt;Thanks for your quick analysis and response&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 10:07:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-use-arcpy-env-with-multithreading/m-p/1263439#M66118</guid>
      <dc:creator>JörgEbert</dc:creator>
      <dc:date>2023-03-02T10:07:21Z</dc:date>
    </item>
  </channel>
</rss>

