<?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 GP Service Publish Fails in ArcGIS Desktop &amp; ArcGIS Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/gp-service-publish-fails-in-arcgis-desktop-arcgis/m-p/301841#M23472</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the code snippet that was added and it's able to run the Toolbox but when ever i try to Publish as GP service, ArcMap/ArcCatalog crashes and not that much information is there in the dump file. It mentions stack overflow exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Main aim is to process huge set of data using chunks instead of querying all the data at once which was having some performance issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a) First Get set of ObjectID's (May be 100000)&lt;/P&gt;&lt;P&gt;b) Call the below generate_chunk --&amp;gt; Which passes list of 10000 Id's 10 time&lt;/P&gt;&lt;P&gt;c) Call the process_chunk which inturn calls the map service for 10000 Id's at a time and get the response JSON.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;def &lt;/SPAN&gt;generate_chunk(l, chunk_size):
    &lt;SPAN style="color: #808080;"&gt;'''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        Build chunk
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        l: Input Object Ids.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        chunk_size: the size of chunk.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    '''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;remainder = &lt;SPAN style="color: #000080;"&gt;len&lt;/SPAN&gt;(l) % chunk_size
    &lt;SPAN style="color: #808080;"&gt;# print(remainder)
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;remainder != &lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;:
        chunk_length = &lt;SPAN style="color: #000080;"&gt;int&lt;/SPAN&gt;(&lt;SPAN style="color: #000080;"&gt;len&lt;/SPAN&gt;(l) / chunk_size)
        chunk = [l[i * chunk_size:i * chunk_size + chunk_size] &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;i &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;range&lt;/SPAN&gt;(chunk_length)]
        chunk.append(l[-remainder:])
        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return &lt;/SPAN&gt;chunk
    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else&lt;/SPAN&gt;:
        chunk_length = &lt;SPAN style="color: #000080;"&gt;int&lt;/SPAN&gt;(&lt;SPAN style="color: #000080;"&gt;len&lt;/SPAN&gt;(l) / chunk_size)
        chunk = [l[i * chunk_size:i * chunk_size + chunk_size] &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;i &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;range&lt;/SPAN&gt;(chunk_length)]
        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return &lt;/SPAN&gt;chunk


&lt;SPAN style="color: #000080; font-weight: bold;"&gt;def &lt;/SPAN&gt;process_chunk(chunk, serviceURL):
    &lt;SPAN style="color: #808080;"&gt;'''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        Process the chunk and return map service json
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    '''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;try&lt;/SPAN&gt;:
        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;item &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;chunk:&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;            &lt;/SPAN&gt;objectIds = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;','&lt;/SPAN&gt;.join([&lt;SPAN style="color: #000080;"&gt;str&lt;/SPAN&gt;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/info.png" /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;i &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;item])
            url_data = urllib.parse.urlencode({&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'f'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'json'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'where'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'1=1'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'outFields'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'*'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'returnZ'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'true'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'objectIds'&lt;/SPAN&gt;: objectIds})
            url_data = url_data.encode(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'utf-8'&lt;/SPAN&gt;)
&lt;SPAN style="color: #808080;"&gt;            &lt;/SPAN&gt;req = urllib.request.Request(serviceURL, url_data)
            results = json.load(urllib.request.urlopen(req))&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;            &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;yield &lt;/SPAN&gt;results
    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;except &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;Exception&lt;/SPAN&gt;:
        tb = sys.exc_info()[&lt;SPAN style="color: #0000ff;"&gt;2&lt;/SPAN&gt;]
        &lt;SPAN style="color: #808080;"&gt;tbinfo &lt;/SPAN&gt;= traceback.format_tb(tb)[&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;]
        pymsg = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Error getting the JSON from ArcGIS Service:&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;\n&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;    " &lt;/SPAN&gt;+ \
                &lt;SPAN style="color: #000080;"&gt;str&lt;/SPAN&gt;(sys.exc_type) + &lt;SPAN style="color: #008000; font-weight: bold;"&gt;": " &lt;/SPAN&gt;+ &lt;SPAN style="color: #000080;"&gt;str&lt;/SPAN&gt;(sys.exc_value) + &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;\n&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"
&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;        &lt;/SPAN&gt;AddMsgAndPrint(pymsg)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is causing StackOverFLowException and not only it crashes ArcGIS Desktop it also crashes ArcGIS PRO 2.4&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 14:28:49 GMT</pubDate>
    <dc:creator>RachappaBellappa2</dc:creator>
    <dc:date>2021-12-11T14:28:49Z</dc:date>
    <item>
      <title>GP Service Publish Fails in ArcGIS Desktop &amp; ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/gp-service-publish-fails-in-arcgis-desktop-arcgis/m-p/301841#M23472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the code snippet that was added and it's able to run the Toolbox but when ever i try to Publish as GP service, ArcMap/ArcCatalog crashes and not that much information is there in the dump file. It mentions stack overflow exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Main aim is to process huge set of data using chunks instead of querying all the data at once which was having some performance issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a) First Get set of ObjectID's (May be 100000)&lt;/P&gt;&lt;P&gt;b) Call the below generate_chunk --&amp;gt; Which passes list of 10000 Id's 10 time&lt;/P&gt;&lt;P&gt;c) Call the process_chunk which inturn calls the map service for 10000 Id's at a time and get the response JSON.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;def &lt;/SPAN&gt;generate_chunk(l, chunk_size):
    &lt;SPAN style="color: #808080;"&gt;'''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        Build chunk
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        l: Input Object Ids.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        chunk_size: the size of chunk.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    '''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;remainder = &lt;SPAN style="color: #000080;"&gt;len&lt;/SPAN&gt;(l) % chunk_size
    &lt;SPAN style="color: #808080;"&gt;# print(remainder)
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;remainder != &lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;:
        chunk_length = &lt;SPAN style="color: #000080;"&gt;int&lt;/SPAN&gt;(&lt;SPAN style="color: #000080;"&gt;len&lt;/SPAN&gt;(l) / chunk_size)
        chunk = [l[i * chunk_size:i * chunk_size + chunk_size] &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;i &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;range&lt;/SPAN&gt;(chunk_length)]
        chunk.append(l[-remainder:])
        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return &lt;/SPAN&gt;chunk
    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else&lt;/SPAN&gt;:
        chunk_length = &lt;SPAN style="color: #000080;"&gt;int&lt;/SPAN&gt;(&lt;SPAN style="color: #000080;"&gt;len&lt;/SPAN&gt;(l) / chunk_size)
        chunk = [l[i * chunk_size:i * chunk_size + chunk_size] &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;i &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;range&lt;/SPAN&gt;(chunk_length)]
        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return &lt;/SPAN&gt;chunk


&lt;SPAN style="color: #000080; font-weight: bold;"&gt;def &lt;/SPAN&gt;process_chunk(chunk, serviceURL):
    &lt;SPAN style="color: #808080;"&gt;'''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        Process the chunk and return map service json
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    '''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;try&lt;/SPAN&gt;:
        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;item &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;chunk:&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;            &lt;/SPAN&gt;objectIds = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;','&lt;/SPAN&gt;.join([&lt;SPAN style="color: #000080;"&gt;str&lt;/SPAN&gt;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/info.png" /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;i &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;item])
            url_data = urllib.parse.urlencode({&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'f'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'json'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'where'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'1=1'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'outFields'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'*'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'returnZ'&lt;/SPAN&gt;: &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'true'&lt;/SPAN&gt;,
                                         &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'objectIds'&lt;/SPAN&gt;: objectIds})
            url_data = url_data.encode(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'utf-8'&lt;/SPAN&gt;)
&lt;SPAN style="color: #808080;"&gt;            &lt;/SPAN&gt;req = urllib.request.Request(serviceURL, url_data)
            results = json.load(urllib.request.urlopen(req))&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;            &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;yield &lt;/SPAN&gt;results
    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;except &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;Exception&lt;/SPAN&gt;:
        tb = sys.exc_info()[&lt;SPAN style="color: #0000ff;"&gt;2&lt;/SPAN&gt;]
        &lt;SPAN style="color: #808080;"&gt;tbinfo &lt;/SPAN&gt;= traceback.format_tb(tb)[&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;]
        pymsg = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Error getting the JSON from ArcGIS Service:&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;\n&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;    " &lt;/SPAN&gt;+ \
                &lt;SPAN style="color: #000080;"&gt;str&lt;/SPAN&gt;(sys.exc_type) + &lt;SPAN style="color: #008000; font-weight: bold;"&gt;": " &lt;/SPAN&gt;+ &lt;SPAN style="color: #000080;"&gt;str&lt;/SPAN&gt;(sys.exc_value) + &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;\n&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"
&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;        &lt;/SPAN&gt;AddMsgAndPrint(pymsg)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is causing StackOverFLowException and not only it crashes ArcGIS Desktop it also crashes ArcGIS PRO 2.4&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:28:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/gp-service-publish-fails-in-arcgis-desktop-arcgis/m-p/301841#M23472</guid>
      <dc:creator>RachappaBellappa2</dc:creator>
      <dc:date>2021-12-11T14:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: GP Service Publish Fails in ArcGIS Desktop &amp; ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/gp-service-publish-fails-in-arcgis-desktop-arcgis/m-p/301842#M23473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try chunks of 1000 records.&amp;nbsp; In some cases that's the most it can handle at once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://enterprise.arcgis.com/en/server/latest/publish-services/windows/large-dataset-upload-and-download-considerations.htm" title="https://enterprise.arcgis.com/en/server/latest/publish-services/windows/large-dataset-upload-and-download-considerations.htm"&gt;Large dataset upload and download considerations—Documentation | ArcGIS Enterprise&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2019 17:54:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/gp-service-publish-fails-in-arcgis-desktop-arcgis/m-p/301842#M23473</guid>
      <dc:creator>JayJohnson6</dc:creator>
      <dc:date>2019-07-24T17:54:04Z</dc:date>
    </item>
  </channel>
</rss>

