Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
Running nested functions using numba

I am trying to use numba recently to speedup parts of my code in python. I was trying to run function 1 from inside function 2 while they are both compiled with numba but it is not working. Here is my code:

import numba as nb
from math import acos
from time import time

@nb.jit("void()")
def myfunc():
    s = 0
    for i in range(10000000):
        s += acos(0.5)
    print('The sum is: ', s)


@nb.jit("void()")
def myfunc2():
    myfunc()


tic = time()
myfunc2()
toc = time()
print(toc-tic)

When I call myfunc() the code works and I get a result much faster than when I am not using numba. However, when I call the myfunc2 I see this error:

 File "~/.spyder-py3/temp.py", line 22, in <module>
    myfunc2()

RuntimeError: missing Environment

Anybody has any ideas why calling a function from insdie another is not working in this case?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Numba v0.39+

A fix was introduced in v0.39. As per the Release Notes:

PR #2986: Fix environment propagation

See github pull #2986 for more details.

Numba pre-v0.39

This is a known issue. As described in github issue #2411:

Seems like the environment pointer is not passed properly across nopython functions.

Amending as below to remove print() from numba functions should fix this:

import numba as nb
from math import acos
from time import time

@nb.jit("void()")
def myfunc():
    s = 0
    for i in range(10000000):
        s += acos(0.5)
    return s

@nb.jit("void()")
def myfunc2():
    return myfunc()

tic = time()
x = myfunc2()  # 10471975.511390356
toc = time()
print(toc-tic)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda