broken pipes, import errors (LONG, INVOLVED)

Bengt Richter bokr at oz.net
Fri Mar 8 22:30:51 EST 2002


On Fri, 8 Mar 2002 16:13:54 -0800, Geoff Gerrietts <geoff at gerrietts.net> wrote:

>
>At work, I'm seeing an "interesting" problem in my production
>environment, or maybe two problems. It's one of those problems that
[...]
>
>  "This" is extremely curious. In one of our Zope products, we have a
>  sequence of logic that looks something like this:
>
>  > statement = "import module.submodule.SubSubModule"
>  > object_nm = "module.submodule.SubSubModule.Object"
>  >
>  > exec statement
>  > object = eval(object_nm)
>
>  Obviously, the names have been changed to protect the innocent and reduce
>  the complications.
>
>  When Zope starts back up, the app will execute this block of statements
>  one or more times for several different values of "statement" and
>  "object_nm".

I don't have a clue about your situation, but it strikes me that exec and eval both
use name spaces (local and global dictionaries) that you could specify, but don't.

I'm wondering if the default (current scope) is ok in your context.

If you are repeatedly reusing the same current scope (e.g., doing those exec and eval
lines inside a loop) for unrelated things, maybe there are name collisions?

Maybe logging the output of dir() before and after those lines would reveal something?
Or try specifying local and global dicts and .clear() them after use (maybe the default
environment is keeping something alive that should get garbage-collected and have its
destructor executed? Or maybe one finally does fire off after a same-name rebinding
of a reference, and the old destructor is doing inappropriate cleanup for the new environment?
How does memory usage look?)

If you specify dictionaries for exec and eval, be wary of just passing anonymous {}.
Give them separate names and assign them separately, unless you want to
use the same one. I.e., dloc={}; dglob={} and they won't clear by themselves, so dloc.clear();
dglob.clear() when you want them to be fresh for the next loop (if that's what you have).
If you pass {} to exec and eval, you won't be able to clear it,  and you won't have changed
much.

These are just ideas trying to jog your thoughts, hopefully helpfully ;-)
No specific recommendations -- you'll have to figure what's appropriate for your situation.

Regards,
Bengt Richter




More information about the Python-list mailing list