Send SigTo() object to child process

Skip to first unread message


Sep 21, 2021, 8:39:14 AM9/21/21
I want to call a child process that will set values to a couple of
SigTo() objects. I've seen the examples in Pyo's documentation with the
SharedTable() approach, but I was wandering if it's possible to do
something like the following:

''' Script called subproc_script that will be loaded in a terminal

import multiprocessing as mp

def subproc(siglist):
    lst = [0, 0]
    # do some processing here
    for i in range(2):

def parentproc(siglist):
    p = mp.Process(target=subproc, args=(siglist,))

The above code should be imported in a terminal session and called this way

import subproc_script as sub

sigs = [SigTo(0) for i in range(2)]

Of course this doesn't work. There is no error produced, but the values
of the SigTo() objects do now change in the terminal.

Any ideas?

Alexandros Drymonitis

Sep 22, 2021, 7:26:27 AM9/22/21
to pyo-discuss
Here's another attempt, following the multiprocessing example of sharing audio signals. This script is called
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._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:
                               self._capital = CountryInfo(list(pycountry.countries)[randrange(self._num_countries)].name).capital()
                       # some countries produce key errors
                       except KeyError:
               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
               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())
t = SharedTable(["/lat", "/lng"], False, _s_.getBufferSize())
l = TableScan(t)
The thing is that the last line produces a "bad code" error. When I try to import the 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?

Alexandros Drymonitis

Sep 29, 2021, 2:09:52 AM9/29/21
to pyo-discuss
Eventually, I went with OSC, so the child process is launched and sends its values with OSC to a OscDataReceive() object, which calls a function to update the values of the two SigTo() objects. Worked fine, so I won't bother any longer with the code above.
Reply all
Reply to author
0 new messages