Calling Python from Go In Memory
summary
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
chapters (10)
- 0:00Introduction
- 1:46Why not RPC
- 2:51Using C as glue
- 4:39Example setup
- 6:01Loading Python function
- 8:52Calling Python from Go
- 12:40Handling memory safely
- 16:55Building the code
- 19:46Thread safety and improvements
- 21:11Q&A and resources








