~/talk

Calling Python from Go In Memory

Talkat FOSDEM 2021 · on Saturday, 2021-02-06· at 15:30· D.go· [python, go]

Embeds CPython into Go via cgo glue so Go float64 slices become NumPy arrays with no serialization, calling Python functions like detect that use PyArray_SimpleNewFromData to view Go memory directly and returning outlier indices (z‑score > 3). It copies back only the usually‑small index array into a Go slice (protecting against >1GB), manages PyObject reference counts, and requires dynamic numpy include discovery via python -c and care for GIL/thread-safety. Risky but low‑overhead.

AI-written summary · about

  1. 0:00Introduction
  2. 1:46Why not RPC
  3. 2:51Using C as glue
  4. 4:39Example setup
  5. 6:01Loading Python function
  6. 8:52Calling Python from Go
  7. 12:40Handling memory safely
  8. 16:55Building the code
  9. 19:46Thread safety and improvements
  10. 21:11Q&A and resources
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.