Here's another attempt, following the multiprocessing example of sharing audio signals. This script is called gmaps.py:
```
import multiprocessing as mp
import googlemaps
from countryinfo import CountryInfo
import pycountry
from random import randrange
from pyo import *
class LatLng(mp.Process):
def __init__(self, buf_size):
super(LatLng, self).__init__()
self._bufsize = buf_size
def run(self):
self.server = Server()
self.server.setInOutDevice(2)
self.server.boot()
self.server.start()
self._writetab = SharedTable(["/lat", "/lng"], True, self._bufsize)
self._sigs = Sig([0, 0])
self._capital = None
self._gmaps = googlemaps.Client(key=key)
self._num_countries = len(pycountry.countries)
def getloc(self):
while self._capital is None:
try:
self._capital = CountryInfo(list(pycountry.countries)[randrange(self._num_countries)].name).capital()
# some countries produce key errors
except KeyError:
pass
geocode_result = self._gmaps.geocode(self._capital)
lat_lng = [abs(geocode_result[0]['geometry']['location']['lat']), abs(geocode_result[0]['geometry']['location']['lng'])]
self._capital = None
self._sigs.setValue(lat_lng)
rec = TableFill(self._writesigs, self._writetab)
```
This has to run inside Pure Data with the [pyo~] external. The idea is that the main script loaded in [pyo~] is the following:
```
import gmaps as gm
loc = gm.LatLng(_s_.getBufferSize())
loc.start()
t = SharedTable(["/lat", "/lng"], False, _s_.getBufferSize())
l = TableScan(t)
loc.getloc()
```
The thing is that the last line produces a "bad code" error. When I try to import the gmaps.py script in a terminal, a get an error on `loc.start()` saying that the server has not been started. In Pd though, I don't get an error there, but only when I call `loc.getloc()`. Since Pd doens't output enough information on errors, but only the "bad code" message, and since in the terminal I get an error earlier than that, it's hard to trace what is going on. Can someone help me?