<?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 Python collision with stand alone ArcGISPro application in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-collision-with-stand-alone-arcgispro/m-p/1041302#M39040</link>
    <description>&lt;P&gt;In the attached video I demonstrate a case where Python.NET code is running while ArcGIS.Core is initialized. Code fails on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;some&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;commands. This is probably due to the internal implementation of ArcGISPro.Core. It is either using Python.NET or uses a different Python to C++ marshaling.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.dropbox.com/s/dkndivr6p4ygqai/esr-python-collision.mp4?dl=0" target="_blank" rel="noopener"&gt;https://www.dropbox.com/s/dkndivr6p4ygqai/esr-python-collision.mp4?dl=0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I run the application without initializing the host – it passes the Python call successfully (sec 16 )&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I initialize the Thread with Host.Initialize()&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I run the same code and it throws an exception&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The exception is of a generic undefined error.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;“External component has thrown an exception. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.”&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;It seems that Host.Initialize() &amp;nbsp;gets control over all the threads, while Python is attempting to do the same.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Python.Net allows users to run python code form .net environment. I use “pythonnet_netstandard_py37_win” Nuget package which is in full compatibility with ArcGIS pro 2.7 (and python 3.7 ).&lt;/P&gt;&lt;P&gt;The same code runs successfully end to end when Host.Initialize() is not running in the same application.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Failed Attempts:&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Creating a new thread in STA and MTA compartments prior&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Using Default and Current TaskSchedulers.&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Creating a dedicated TaskFactory&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;init&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Creating a dedicated TaskFactory&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;after&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;init&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The collision is happening on C++ authorization level. Thus has to be addressed by the ESRI team.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have created a repository to replicate the issue both in running and not running state is provided here&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/gis-geodata/arc-gispro-python-net-licensing-collision" target="_blank" rel="noopener"&gt;gis-geodata/arc-gispro-python-net-licensing-collision (github.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;To replicate the exceptions &lt;A href="https://github.com/gis-geodata/arc-gispro-python-net-licensing-collision/blob/a4abfb72b7ded11c3c54474b8e608f183d1b1d2a/Collision.Runner/Program.cs#L29" target="_self"&gt;comment out this line&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Full StackTrace&lt;/P&gt;&lt;P&gt;System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.Runtime.PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.PyObject.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object&amp;amp; result)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at CallSite.Target(Closure , CallSite , Object , PyString )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Cadaster.Gateway.EnvironmentConfiguration.PythonScripts.CreateCityUser(String cityName, Object arcpy, DataBase database) in I:\Cadaster\Gateway\EnvironmentConfiguration\PythonScripts.cs:line 108&lt;/P&gt;</description>
    <pubDate>Sat, 27 Mar 2021 15:38:24 GMT</pubDate>
    <dc:creator>dkuida</dc:creator>
    <dc:date>2021-03-27T15:38:24Z</dc:date>
    <item>
      <title>Python collision with stand alone ArcGISPro application</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-collision-with-stand-alone-arcgispro/m-p/1041302#M39040</link>
      <description>&lt;P&gt;In the attached video I demonstrate a case where Python.NET code is running while ArcGIS.Core is initialized. Code fails on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;some&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;commands. This is probably due to the internal implementation of ArcGISPro.Core. It is either using Python.NET or uses a different Python to C++ marshaling.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.dropbox.com/s/dkndivr6p4ygqai/esr-python-collision.mp4?dl=0" target="_blank" rel="noopener"&gt;https://www.dropbox.com/s/dkndivr6p4ygqai/esr-python-collision.mp4?dl=0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I run the application without initializing the host – it passes the Python call successfully (sec 16 )&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I initialize the Thread with Host.Initialize()&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I run the same code and it throws an exception&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The exception is of a generic undefined error.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;“External component has thrown an exception. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.”&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;It seems that Host.Initialize() &amp;nbsp;gets control over all the threads, while Python is attempting to do the same.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Python.Net allows users to run python code form .net environment. I use “pythonnet_netstandard_py37_win” Nuget package which is in full compatibility with ArcGIS pro 2.7 (and python 3.7 ).&lt;/P&gt;&lt;P&gt;The same code runs successfully end to end when Host.Initialize() is not running in the same application.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Failed Attempts:&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Creating a new thread in STA and MTA compartments prior&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Using Default and Current TaskSchedulers.&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Creating a dedicated TaskFactory&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;init&lt;/P&gt;&lt;P&gt;·&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Creating a dedicated TaskFactory&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;after&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;init&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The collision is happening on C++ authorization level. Thus has to be addressed by the ESRI team.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have created a repository to replicate the issue both in running and not running state is provided here&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/gis-geodata/arc-gispro-python-net-licensing-collision" target="_blank" rel="noopener"&gt;gis-geodata/arc-gispro-python-net-licensing-collision (github.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;To replicate the exceptions &lt;A href="https://github.com/gis-geodata/arc-gispro-python-net-licensing-collision/blob/a4abfb72b7ded11c3c54474b8e608f183d1b1d2a/Collision.Runner/Program.cs#L29" target="_self"&gt;comment out this line&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Full StackTrace&lt;/P&gt;&lt;P&gt;System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.Runtime.PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Python.Runtime.PyObject.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object&amp;amp; result)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at CallSite.Target(Closure , CallSite , Object , PyString )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; at Cadaster.Gateway.EnvironmentConfiguration.PythonScripts.CreateCityUser(String cityName, Object arcpy, DataBase database) in I:\Cadaster\Gateway\EnvironmentConfiguration\PythonScripts.cs:line 108&lt;/P&gt;</description>
      <pubDate>Sat, 27 Mar 2021 15:38:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-collision-with-stand-alone-arcgispro/m-p/1041302#M39040</guid>
      <dc:creator>dkuida</dc:creator>
      <dc:date>2021-03-27T15:38:24Z</dc:date>
    </item>
  </channel>
</rss>

