[Python-Dev] PEP 273: Import Modules from Zip Archives

Finn Bock bckfnn@worldonline.dk
Mon, 29 Oct 2001 19:16:21 GMT


[me]

> myself), I just didn't dare to put such a limit on my jython
> implementation.

[James C. Ahlstrom]

>I don't understand the jpython implementation, so please point out
>all problems so we can fix them now.

A naive implementation (like the first one I made for Jython) does not
try to handle the cleanup issues.

For example, how much memory have been consumed and not freed after the
last statement in this little silly program:

import sys, zipfile, time

zip = zipfile.ZipFile("archive.zip", "w")
for i in range(10000):
    entry = zipfile.ZipInfo()
    entry.filename = "module%06d.py" % i
    entry.date_time = time.gmtime(time.time())
    zip.writestr(entry, "# Not used\n")
zip.close()

sys.path.append("archive.zip")
try:
   import notfound
except ImportError:
   pass
sys.path.pop()


If I read your preliminary patch correctly, the 10000 entries will
remain in the ArchiveMembers dict forever and that is perfectly fine
after Guido comments on sys.path being mostly a static feature.

Jython manage to clean the member-cache when an archive is removed from
sys.path but is was quite tricky to achieve. We do it by replacing zip
entries in sys.path (like "archive.zip") with a subclass of string
(SyspathArchive) that also holds a reference to the member cache. From
pythons POV the sys.path entry is still a string with the same value
(but with a different id).

regards,
finn