Reputation: 967
I have a list of addresses and I just wind up getting a Kill 9 error when I try to add coordinates.
Is it timing out? I added sleep times to prevent it .
I get this error Killed: 9
def do_geocode(Nominatim, address):
time.sleep(3)
try:
return Nominatim.geocode(address)
except GeocoderTimedOut:
return do_geocode(Nominatim,address)
def addCoordinates(businessList):
businessList[0] = ["pageNum","entryNum","name","address","tagOne","tagTwo","tagThree","geoAddress","appendedLocation","latitude","longitude","key"]
geolocator = Nominatim(timeout=None)
z = 0
i=1
while i < len(businessList):
longitude = ""
latitude = ""
geoLocation = ""
geoAddress = ""
entry = []
appendedLocation = (businessList[i][3] + ", San Francisco")
geoLocation = do_geocode(geolocator, appendedLocation)
if geoLocation is not None:
geoAddress = geoLocation.address
latitude = geoLocation.latitude
longitude = geoLocation.longitude
entry = [geoAddress, appendedLocation, str(latitude), str(longitude)]
j=0
while j < len(entry):
businessList[i] += [entry[j]]
j+=1
print("coordinates added")
z +=1
print(z)
i+=1
Upvotes: 1
Views: 160
Reputation: 898
Killed: 9
probably means that your Python script has been terminated by something in your OS (perhaps OOM killer?). Ensure your script doesn't occupy the whole available memory of the machine.
For geopy specifically I'd suggest to take a look at the RateLimiter class. Also note that you need to specify your unique User Agent when using Nominatim (which is explained in the Nominatim class docs). You'd get something like this:
from geopy.extra.rate_limiter import RateLimiter
def addCoordinates(businessList):
businessList[0] = ["pageNum","entryNum","name","address","tagOne","tagTwo","tagThree","geoAddress","appendedLocation","latitude","longitude","key"]
geolocator = Nominatim(user_agent="specify_your_app_name_here", timeout=20)
geocode = RateLimiter(
geolocator.geocode,
min_delay_seconds=3.0,
error_wait_seconds=3.0,
swallow_exceptions=False,
max_retries=10,
)
z = 0
i=1
while i < len(businessList):
longitude = ""
latitude = ""
geoLocation = ""
geoAddress = ""
entry = []
appendedLocation = (businessList[i][3] + ", San Francisco")
geoLocation = geocode(appendedLocation)
if geoLocation is not None:
geoAddress = geoLocation.address
latitude = geoLocation.latitude
longitude = geoLocation.longitude
entry = [geoAddress, appendedLocation, str(latitude), str(longitude)]
j=0
while j < len(entry):
businessList[i] += [entry[j]]
j+=1
print("coordinates added")
z +=1
print(z)
i+=1
Upvotes: 1