[SciPy-User] RuntimeError: cannot unmarshal code objects in restricted execution mode

Robert Kern robert.kern at gmail.com
Thu Dec 8 15:36:29 EST 2011


2011/12/8 Vladimír Černý <blackvladimir at gmail.com>:
> Hi,
>
> when i import scipy in restricted mode (eval function, with changed
> builtins) it ends with exception:
>
> RuntimeError: cannot unmarshal code objects in restricted execution mode.
>
> On the second try it works without exception.

The reason it "works" the second time is that the scipy module has
already been added to sys.modules, so it does not try to import
anything again. You will see that sys.modules['scipy'] exists after
the first failing eval(). However, I'm certain that the RuntimeError
prevented a number of things from being initialized, so I doubt that
it is fully functional. The second import does not really succeed;
it's a no-op.

> Code to reproduce error:
>
> myb = {}
> for b in dir(__builtins__):
>   myb[b]=getattr(__builtins__,b)
> gl=dict()
> gl['__builtins__'] = myb
> c=compile('import scipy','file','exec')
> eval(c,gl)

By the way, you should be using "exec c in gl" here since code
contains a statement, not an expression.

I'm afraid that I don't have any insight into the ultimate cause of
the error or how to fix it.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the SciPy-User mailing list