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

Vladimír Černý blackvladimir at gmail.com
Thu Dec 8 16:06:56 EST 2011


Thanks

The code which fail can look like this:

myb = {}
for b in dir(__builtins__):
   myb[b]=getattr(__builtins__,b)
gl=dict()
gl['__builtins__'] = myb
exec('import scipy',gl)



On Thu, 08 Dec 2011 21:36:29 +0100, Robert Kern <robert.kern at gmail.com>  
wrote:

> 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.



More information about the SciPy-User mailing list