Content-Length: 271592 | pFad | https://github.com/sbinet/go-python/issues/102

48 panic when register callback from go into python as module · Issue #102 · sbinet/go-python · GitHub
Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

panic when register callback from go into python as module #102

Closed
@xiyanxiyan10

Description

@xiyanxiyan10

code

package pythonbind

import "C"
import (
	"fmt"
	"github.com/sbinet/go-python"
	"time"
)

type Go2Python struct {
	fileName string
}

func Hello(self, args *python.PyObject) *python.PyObject {
	fmt.Printf("Hello world")
	return python.Py_None
}

// Run run the scripts
func (g Go2Python) Run() error {
	if err := python.Initialize(); err != nil {
		return err
	}
	methods := make([]python.PyMethodDef,1)
	method := &methods[0]
	method.Name = "hello"
	method.Meth = Hello
	method.Doc = "hello world"
	method.Flags = python.MethNoArgs

	_, err := python.Py_InitModule("snack", methods)
	if err != nil {
		panic(err)
	}
	if err := python.PyRun_SimpleFile(g.fileName); err != nil {
		return err
	}
	if err := python.Finalize(); err != nil {
		return err
	}
	time.Sleep(time.Minute * 5)
	return nil
}

when I run function run, panic happen in Py_InitModule

API server listening at: 127.0.0.1:60703
=== RUN   TestSum
--- FAIL: TestSum (7.60s)
panic: runtime error: cgo argument has Go pointer to Go pointer [recovered]
	panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 19 [running]:
testing.tRunner.func1(0xc0000e0100)
	/Users/xiyanxiyan10/go1.13/src/testing/testing.go:874 +0x60f
panic(0x4181560, 0xc0000984e0)
	/Users/xiyanxiyan10/go1.13/src/runtime/panic.go:679 +0x1e0
github.com/sbinet/go-python.cpyMethodDefs.func1(0x5003380, 0xc000049b78, 0xc0000ba080)
	/Users/xiyanxiyan10/project/goquant/back/pkg/mod/github.com/sbinet/go-python@v0.0.0-20190615090516-46d882be3991/heap.go:31 +0x12c
github.com/sbinet/go-python.cpyMethodDefs(0x41b0201, 0x5, 0xc000049e38, 0x1, 0x1, 0x0)
	/Users/xiyanxiyan10/project/goquant/back/pkg/mod/github.com/sbinet/go-python@v0.0.0-20190615090516-46d882be3991/heap.go:31 +0x2eb
github.com/sbinet/go-python.Py_InitModule(0x41b0201, 0x5, 0xc000049e38, 0x1, 0x1, 0x0, 0x0, 0x0)
	/Users/xiyanxiyan10/project/goquant/back/pkg/mod/github.com/sbinet/go-python@v0.0.0-20190615090516-46d882be3991/heap.go:42 +

go version 1.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/sbinet/go-python/issues/102

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy