JuliaPy / JuliaPy/PyCall.jl

thread safety

Abierto
#882 30 comentarios 1 reacción 0 asignados Ver en GitHub
bug
Lenguaje dominante
Julia
Estrellas
1.5k
Forks
186
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

If Julia's `Threads.nthreads() > 1`, we may want to do some more work to ensure thread safety. In particular:

* Call `PyEval_InitThreads()` in `__init__` (this is only needed for Python ≤ 3.6, and is a no-op in Python ≥ 3.7).
* Acquire the GIL in the PyObject `finalizer`, by calling `PyGILState_Ensure` (returns an [`enum`](https://github.com/python/cpython/blob/63298930fb531ba2bb4f23bc3b915dbf1e17e9e1/Include/pystate.h#L95-L96), i.e. a `Cint` in Julia) and `PyGILState_Release`. This is because the Julia GC may be called from threads other than the main thread, so we need to ensure that we hold Python's GIL before decref-ing.

We might also expose an API to acquire the GIL, but in general I would recommend that user code should only call Python from the main thread.

See [this forum post](https://discourse.julialang.org/t/help-with-pycall-related-segfault/55998?u=stevengj) and #881 for a possible test case.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Empieza inspeccionando la ruta package __init__ y el finalizador de PyObject; después, revisa el posible caso de prueba referenciado en #881. Comprueba el comportamiento de la versión de Python en torno a la inicialización de hilos y la ejecución de finalizadores por parte de Julia GC desde hilos que no son el principal. Se considera terminado cuando los casos relevantes de seguridad de hilos ya no corren el riesgo de realizar llamadas a la API de Python sin el GIL.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
julia, 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.