<?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: Python script never terminates in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186442#M6330</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rebecca&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I today ran your script, the one that identifies broken sources,&lt;/P&gt;&lt;P&gt;and it ran without any problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So there does appear to be something wrong with my Python Code.&lt;/P&gt;&lt;P&gt;I am hard pressed to figure out what.&lt;/P&gt;&lt;P&gt;I have many maps, in structure they are very much the same,&lt;/P&gt;&lt;P&gt;but only one causes this problem.&lt;/P&gt;&lt;P&gt;I will compare my code with yours.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Sep 2015 01:26:50 GMT</pubDate>
    <dc:creator>RobertStevens</dc:creator>
    <dc:date>2015-09-02T01:26:50Z</dc:date>
    <item>
      <title>Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186429#M6317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can someone divine why the attached python script never terminates?&lt;/P&gt;&lt;P&gt;I am running with ArcGIS10.3.1 basic.&lt;/P&gt;&lt;P&gt;When I run this using 32-bit python it gets to the last layer&lt;/P&gt;&lt;P&gt;and the terminates with a segmentation violation.&lt;/P&gt;&lt;P&gt;With a 64-bit python it never terminates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The program runs fine on other maps I have, but&lt;/P&gt;&lt;P&gt;one in particular gives this problem. AFAIK&lt;/P&gt;&lt;P&gt;the map in question is not in any relevant&lt;/P&gt;&lt;P&gt;sense different from those on which the&lt;/P&gt;&lt;P&gt;script runs ok.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Aug 2015 23:40:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186429#M6317</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2015-08-28T23:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186430#M6318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;zips don't open easily on iThingys, if the script isn't too long, copy, paste and format it using the python​ syntax highligher accesses with the &lt;STRONG&gt;&amp;gt;&amp;gt; &lt;/STRONG&gt;bu​tton using the advanced editor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Aug 2015 01:30:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186430#M6318</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-08-29T01:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186431#M6319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've posted you script, as is (after the unzip), and it looks like your indentation is off onmany of the likes.&amp;nbsp; 36, 37, and 55 have an extra space in front.&amp;nbsp; And some of the if and elif:&amp;nbsp; statements don't seem to be indented at all, so thinks wouldn't execute....which may be why the program doesn't end for some mxd's.&amp;nbsp; If these are correct on you side, then it may be something happened in the zip file.&amp;nbsp; Use &lt;A href="https://community.esri.com/migration-blogpost/1070" target="_blank"&gt;Posting Code blocks in the new GeoNet&lt;/A&gt;​&amp;nbsp; to post the corrected copy of your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've gone a completely different route for updating my broken links, since the .sde and .ags connections needed special handling.&amp;nbsp; So I'll be interested if you code (once fixed) handles all those.&amp;nbsp; My process reads from an excel/ (actually csv) file and can change paths, and feature class types, if needed.&amp;nbsp; Seems to be working now, but running a test this weekend.&amp;nbsp; Then I need to clean up the code a bit.&amp;nbsp; You code is much shorted than mine, but not sure if I understand what it does complete (I'm not familiar with the OptionParser or glob for that matter).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import glob
import os
import sys
import arcpy
import arcpy.mapping as mapping
from optparse import OptionParser

# Previous invocations of this script were used to effect the following conversions
# from Program Files (x86)/ArcGIS/Desktop10.0/Business Analyst/US/Data/
# to&amp;nbsp;&amp;nbsp; Business Analyst/2011Data/
# from RLIS_201402&amp;nbsp; to&amp;nbsp; RLIS
# from RLIS_201402&amp;nbsp; to&amp;nbsp; RLIS_WebMercator

parser = OptionParser()
parser.add_option("-f", "--fix", action="store_true", dest="f",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default=False,help="fix the source name")
parser.add_option("-o", "--old-src", action="store", dest="o",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default="RLIS-201402",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; help="the old source file name, or part of a name")
parser.add_option("-n", "--new-src", action="store", dest="n",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default="RLIS",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; help="the new source file name, or part of a name")

(options, args) = parser.parse_args()

old_src = options.o
new_src = options.n

def fixLayer(lyr):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrModified = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isFeatureLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print lyr.name
&amp;nbsp;&amp;nbsp;&amp;nbsp; if old_src in lyr.dataSource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\t\t" + lyr.dataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp; if options.f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrModified = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath(old_src,new_src,False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lyrModified

def fixMap(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxdModified = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; # loop thru all data frames in the map
&amp;nbsp;&amp;nbsp;&amp;nbsp; dataFrames = mapping.ListDataFrames(mxd, '')
&amp;nbsp;&amp;nbsp;&amp;nbsp; for frame in dataFrames:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tframe " + frame.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # get all layers in this data frame
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layers = mapping.ListLayers(mxd, '', frame)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # loop thru all layers in the data frame
&amp;nbsp;&amp;nbsp;&amp;nbsp; print layers
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrModified = fixLayer(lyr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyrModified:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxdModified = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxdModified:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()

def fixit(fullPath,fileName):
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if desc.datatype == "MapDocument":
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fileName
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fixMap(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif desc.datatype == "Layer":
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fileName
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = mapping.Layer(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fixLayer(lyr):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.save()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del lyr

for arg in args:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isdir(arg):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fileName in os.listdir(arg):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(arg, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fixit(fullPath,fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif os.path.isfile(arg):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fixit(arg,arg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arg + " is not a map, nor a layer, nor a directory"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:26:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186431#M6319</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2021-12-11T09:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186432#M6320</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes, you are right.&lt;/P&gt;&lt;P&gt;I don't know how that happened.&lt;/P&gt;&lt;P&gt;It was correct at one time.&lt;/P&gt;&lt;P&gt;I have no idea what Python would do with that&lt;/P&gt;&lt;P&gt;but I will correct it and retry.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Aug 2015 04:21:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186432#M6320</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2015-08-29T04:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186433#M6321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you using a good IDE that shows Python syntax errors?&amp;nbsp; There are many....I use and like Wing.&amp;nbsp; I use the Pro version but there is a free one too.&amp;nbsp; But many others.&amp;nbsp; It would bark at the extra space and would also give you an error when there is a "elif" with nothing to do, etc.&amp;nbsp;&amp;nbsp; Just a suggestion if you aren't using one.&amp;nbsp; If it was in the .zip....no clue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Aug 2015 04:25:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186433#M6321</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-08-29T04:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186434#M6322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I fixed the indentation problems, and Wing seems to say all is OK.&lt;/P&gt;&lt;P&gt;But the behavior is unchanged.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Aug 2015 07:31:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186434#M6322</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2015-08-29T07:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186435#M6323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the code works fine on all other maps, and only crashes on one map, something is likely off with that one map.&amp;nbsp; I have run into issues where MXDs are partially corrupt, not too corrupt for ArcMap to open but corrupt enough that ArcPy scripts will crash.&amp;nbsp; Have you run DocDefragmenter or MXDDoctor on the problem map?&amp;nbsp; If not, it might be worth seeing if running either of those makes a map that doesn't crash.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the MXD is healthy and defragged, there might be a data source in the map that is exposing a bug with ArcPy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Aug 2015 14:29:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186435#M6323</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-08-29T14:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186436#M6324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And to add what Joshua suggested....a SaveAs sometimes fixes slightly corrupted or bloated MXDs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have any .sde, groups, arcgis-server, etc connections in this mxd?&amp;nbsp; And if so, does your code take those different items into consideration?&amp;nbsp;&amp;nbsp; im not sure if hitting one of those items would not let your script terminate, but it know they can/will cause issues when trying to auto fix broken links.​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Aug 2015 16:41:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186436#M6324</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-08-29T16:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186437#M6325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have run the MXD Doctor and the Defrag utility all with no effect.&lt;/P&gt;&lt;P&gt;No the map in question does not have any .sde or server connections&lt;/P&gt;&lt;P&gt;-- all the data is local.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One other thing I should say is that I am&amp;nbsp; presently running this script &lt;/P&gt;&lt;P&gt;to identify layers using a particular dataset. I am not changing anything&lt;/P&gt;&lt;P&gt;(so the -f option is false).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just as an aside: this Python interface of arcpy is so slow. One notices&lt;/P&gt;&lt;P&gt;this also when invoking Python tools from within ArcGIS. Even to bring&lt;/P&gt;&lt;P&gt;up the dialogue screen is sluggish -- 10,15 even sometimes 20 seconds.&lt;/P&gt;&lt;P&gt;Given that Windows itself running under Parallels on my MAcbook Pro&lt;/P&gt;&lt;P&gt;takes a mere 5 seconds to startup, those numbers are astonishing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Aug 2015 19:31:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186437#M6325</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2015-08-29T19:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186438#M6326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code that Rebecca kindly formatted did not properly show indentation&lt;/P&gt;&lt;P&gt;possibly because tabs and spaced were intermingled.&lt;/P&gt;&lt;P&gt;(Though there were the 3 errors she mentioned, since fixed).&lt;/P&gt;&lt;P&gt;I have re-posted the script here with the proper indentation.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import glob
import os
import sys
import arcpy
import arcpy.mapping as mapping
from optparse import OptionParser


# Previous invocations of this script were used to effect the following conversions
# from Program Files (x86)/ArcGIS/Desktop10.0/Business Analyst/US/Data/
# to&amp;nbsp; Business Analyst/2011Data/
# from RLIS_201402&amp;nbsp; to&amp;nbsp; RLIS
# from RLIS_201402&amp;nbsp; to&amp;nbsp; RLIS_WebMercator


parser = OptionParser()
parser.add_option("-f", "--fix", action="store_true", dest="f",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default=False,help="fix the source name")
parser.add_option("-o", "--old-src", action="store", dest="o",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default="RLIS-201402",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; help="the old source file name, or part of a name")
parser.add_option("-n", "--new-src", action="store", dest="n",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default="RLIS",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; help="the new source file name, or part of a name")


(options, args) = parser.parse_args()


old_src = options.o
new_src = options.n


def fixLayer(lyr):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrModified = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isFeatureLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print lyr.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if old_src in lyr.dataSource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\t\t" + lyr.dataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if options.f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrModified = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath(old_src,new_src,False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lyrModified


def fixMap(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxdModified = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; # loop thru all data frames in the map
&amp;nbsp;&amp;nbsp;&amp;nbsp; dataFrames = mapping.ListDataFrames(mxd, '')
&amp;nbsp;&amp;nbsp;&amp;nbsp; for frame in dataFrames:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tframe " + frame.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # get all layers in this data frame
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layers = mapping.ListLayers(mxd, '', frame)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # loop thru all layers in the data frame
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print layers
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrModified = fixLayer(lyr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyrModified:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxdModified = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; if mxdModified:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()


def fixit(fullPath,fileName):
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if desc.datatype == "MapDocument":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fileName
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fixMap(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif desc.datatype == "Layer":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fileName
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = mapping.Layer(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fixLayer(lyr):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.save()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del lyr


for arg in args:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isdir(arg):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fileName in os.listdir(arg):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(arg, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fixit(fullPath,fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif os.path.isfile(arg):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fixit(arg,arg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arg + " is not a map, nor a layer, nor a directory"


exit(0)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:26:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186438#M6326</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2021-12-11T09:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186439#M6327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try adding some print statements to see what layer causes the code to hang.&amp;nbsp; If you change the order of the problem layer, does the code still hang on that layer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 14:16:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186439#M6327</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-08-31T14:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186440#M6328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had already added some print, but I should have reported what I found.&lt;/P&gt;&lt;P&gt;The script does indeed go through all the layers (there is only&lt;/P&gt;&lt;P&gt;one frame in the map in question) and then hangs at the end&lt;/P&gt;&lt;P&gt;(To be more precise: the 64 bit version of python hangs at&lt;/P&gt;&lt;P&gt;the end; the 32 bit version experiences a segmentation violation).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried changing the order of layers. The script always reports&lt;/P&gt;&lt;P&gt;all the layers. Same behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The map in question has many layers, but most of them&lt;/P&gt;&lt;P&gt;are basemap layers which display at different scales.&lt;/P&gt;&lt;P&gt;But the others maps I have are no different in that respect.&lt;/P&gt;&lt;P&gt;I can see nothing special about this map.&lt;/P&gt;&lt;P&gt;All the maps I have use the same basemap layers&lt;/P&gt;&lt;P&gt;but only this particular one (I believe) exhibits this&lt;/P&gt;&lt;P&gt;behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To repeat: I have run Map Doctor and Defragger.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No change.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 17:49:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186440#M6328</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2015-08-31T17:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186441#M6329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert, not that it will fix you issue, but if you want to look at my solution to fixing broken links, I've posted my first version of &lt;A href="https://community.esri.com/migration-blogpost/55043"&gt;Python addin for data inventory and “broken-link” repair.&lt;/A&gt;&amp;nbsp;&amp;nbsp; It's definitely a different approach than your code, but I'd be curious if you have a similar issue on you mxd.&amp;nbsp; If so, than maybe it would point to the mxd and not your script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2015 01:04:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186441#M6329</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-09-01T01:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186442#M6330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rebecca&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I today ran your script, the one that identifies broken sources,&lt;/P&gt;&lt;P&gt;and it ran without any problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So there does appear to be something wrong with my Python Code.&lt;/P&gt;&lt;P&gt;I am hard pressed to figure out what.&lt;/P&gt;&lt;P&gt;I have many maps, in structure they are very much the same,&lt;/P&gt;&lt;P&gt;but only one causes this problem.&lt;/P&gt;&lt;P&gt;I will compare my code with yours.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Sep 2015 01:26:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186442#M6330</guid>
      <dc:creator>RobertStevens</dc:creator>
      <dc:date>2015-09-02T01:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Python script never terminates</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186443#M6331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​Robert, mine tests for all (or most anyway) of the anomalies. Seems like different data types, and TOC-groups, etc. need to be tested differently.....even more so when repairing the broken links.&amp;nbsp; I wouldn't say mine is perfect yet, and I know it could be more efficient, but I'm at the point I need to move on, at least for a while.&amp;nbsp; I'm hoping others give the broken link reporting a try and give feedback.&amp;nbsp; I only have my datasets/mxds to test.&amp;nbsp; So feel free to give scripting feedback....whether I merge it all in or not... .?&amp;nbsp; I wrote it for our users of course, but hoping it can help others.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Sep 2015 01:45:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-never-terminates/m-p/186443#M6331</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-09-02T01:45:10Z</dc:date>
    </item>
  </channel>
</rss>

