Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with importing; must do it twice?

0 views
Skip to first unread message

Aahz

unread,
Jun 13, 2002, 3:49:55 PM6/13/02
to
In article <fgphgus0pv2c7hp8l...@4ax.com>,
Stew LG <stew@ten_INVALID_box.com> wrote:
>
>My web host just switched hardware, and in the process I've been moved
>to Solaris and Python 2.1.1.

Your web host failed to compile Python correctly; talk with them.

>This seemed insane to me, so I tried Python from the command line.
>Same thing, but when I import it *again* it works:

No, it didn't. Python caches import names even when the import fails
(protects against circular references); try using the cgi module for
anything that requires a socket and it'll die. It might work for the
other functions in the cgi module, depending on when cgi tried to import
the socket code.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/

"I had lots of reasonable theories about children myself, until I
had some." --Michael Rios

Peter Hansen

unread,
Jun 17, 2002, 10:19:43 PM6/17/02
to
Aahz wrote:
>
> Python caches import names even when the import fails
> (protects against circular references)

I thought about this for a while and suppose I can see how it
protects against circular reference problems (I'm guessing it
creates a new module object and stores it in sys.modules
immediately upon encountering the import statement, and only
subsequently does it try to import and execute the contents),
but what I don't understand is why it doesn't clean up after
itself in the case of a failed import.

Should it not be considered a bug that a failed import leaves
a broken module around?

Is it possible to redefine this so that it cleanly removes the
newly created reference if an import fails?

Or would it then be a problem that circularly imported modules
might now have references back to a module which appears never
to have been imported (because it failed, and was deleted)?

And have I now answered all my questions? :-)

-Peter

Aahz

unread,
Jun 17, 2002, 10:59:39 PM6/17/02
to
In article <3D0E98BF...@engcorp.com>,

Peter Hansen <pe...@engcorp.com> wrote:
>
>Should it not be considered a bug that a failed import leaves
>a broken module around?

Lots of people think so, but every time this comes up on python-dev,
someone fumbles around and eventually remembers exactly why it has to
work this way -- but I'm never the someone.

Project Vote Smart: http://www.vote-smart.org/

0 new messages