callbacks of python methods across threads doesn't work
- Lenguaje dominante
- Go
- Estrellas
- 2.3k
- Forks
- 136
- Merge medio
- 14 min
- PR fusionados (30 d)
- 2
Descripción
It works fine for functions, just not methods. There is some ambiguity about how the self argument is handled for methods, but presumably that is the crux of the problem.
Tried the following (see bind/symbols.go):
```Go
bstr := fmt.Sprintf("var %s *C.PyObject\n", varnm)
bstr += fmt.Sprintf("_pyargstidx := 0\n")
bstr += fmt.Sprintf("_pyargidx := C.long(0)\n")
if methvar != "" {
bstr += fmt.Sprintf("if C.gopy_method_check(%s) != 0 {\n", methvar)
bstr += fmt.Sprintf("\tC.gopy_incref(%s)\n", methvar)
bstr += fmt.Sprintf("\t%s = C.PyTuple_New(%d)\n", varnm, sz+1)
bstr += fmt.Sprintf("\tC.PyTuple_SetItem(%s, 0, C.PyMethod_Self(%s))\n", varnm, methvar)
bstr += fmt.Sprintf("\t_pyargstidx = 1\n")
bstr += fmt.Sprintf("\t%[1]s = C.PyMethod_Function(%[1]s)\n", methvar)
bstr += fmt.Sprintf("} else {\n")
bstr += fmt.Sprintf("\t%s = C.PyTuple_New(%d)\n", varnm, sz)
bstr += fmt.Sprintf("}\n")
}
```
per this: https://www.reddit.com/r/Python/comments/3618cd/calling_back_python_instance_methods_from_c/
but didn't have any different results relative to just the basic CallObject version.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Start with bind/symbols.go and trace how callbacks for Python functions and methods are assembled, including handling of the self argument and cross-thread invocation. Reproduce the reported difference between functions and methods, then verify that Python instance-method callbacks work across threads without regressing function callbacks.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- go, python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100