[ZODB-Dev] strange testConnection error

Tim Peters tim at zope.com
Mon Mar 14 22:46:23 EST 2005


[John Belmonte]
> Thanks for the analysis Tim.  The situation has to be #3-- I know the
> import error is happening in a restricted mode,

_Now_ you tell us <wink>.

> because that was part of the fight I had with the logging system.  The
> original error message was not seeing the light of day because an
> exception related to restricted mode was happening inside the logging
> module itself.  (In my opinion, if the logging system is that fragile,
> it's not very useful.)

I can't blame the logging module for this.  Nothing in the Python
distribution is tested in restricted execution mode, and most core Python
developers are at best dimly aware of it; I'd be surprised if the logging
module's author even knows about it.  The real mystery here is why you're
getting into it to begin with, not why various things break once you are
(it's largely the _purpose_ of restricted execution mode to prevent code
from doing anything useful <0.7 wink>).

It's very easy to get into it too, but not by accident.  All it keys off of
is whether the binding of name '__builtins__' in the current globals is
identical to the object __builtin__.__dict__.  You're in "restricted
execution mode" if and only if those differ.  Yes, that's obscure.  You can
get into it as simply as this:

>>> def f():
...     pass

# This one is fine:  not restricted.
>>> exec "g = f.func_globals\nprint type(g)\n" in {'f': f}
<type 'dict'>

# But this one is restricted, and .func_globals is off limits then.
>>> exec "g = f.func_globals\nprint type(g)\n" \
...            in {'f': f, '__builtins__': None}
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 1, in ?
RuntimeError: restricted attribute


> If ZODB/ZEO isn't doing it, I don't know how restricted mode is getting
> invoked.  There's nothing like that in my app itself.  I'm fairly sure my
> app is not the problem, because the code was once working fine-- the
> problem began after some routine package upgrades on the machine.  I'll
> have to look to see if mod_python or Quixote might be causing it.

Google finds rare reports of "ImportError: No module named copy_reg", but
the only promising ones of those I found turned out to be due to Mailman
misconfiguration.

Google turns up lots of reports of problems with restricted execution mode
under mod_python, although most of the ones I browsed were a combination of:

  RuntimeError: cannot unmarshal code objects in restricted execution mode

and something-or-other related to XML processing.

If you figure it out, please let us know!  I'd simply try it on a different
box first.



More information about the ZODB-Dev mailing list