I’d recommend using aiosc module instead of pythonosc, just in case you ever need full-duplex communication. Then you can basically do something like following in you grid_key handler:
import asyncio
import monome, aiosc
CSOUND_ADDRESS = ('127.0.0.1', 9000)
class Hello(monome.App):
def on_grid_key(self, x, y, s):
self.grid.led_set(x, y, s)
if s == 1:
freq = (y * self.grid.width + x) * 10
asyncio.ensure_future(aiosc.send(CSOUND_ADDRESS, '/kfreq', freq))
if __name__ == '__main__':
loop = asyncio.get_event_loop()
hello_app = Hello()
asyncio.async(monome.SerialOsc.create(loop=loop, autoconnect_app=hello_app))
loop.run_forever()