[Image-SIG] why does Image.open fail after reload(Image) -- fixable bug ??
Sebastian Haase
haase at msg.ucsf.edu
Mon Apr 14 12:06:53 CEST 2008
On Mon, Apr 14, 2008 at 11:27 AM, Sebastian Haase <haase at msg.ucsf.edu> wrote:
> Hi,
>
> this is a short question:
>
> Why does Image.open fail after reload(Image) ?
>
> Here is what I get :
> {{{
> >>> import Image
> >>> i = Image.open(r"/Users/labuser/Desktop/Picture 5.png")
> >>> i.size
> (1920, 1200)
> >>> reload(Image)
> <module 'Image' from '....../PIL/Image.pyc'>
> >>> i = Image.open("Picture 5.png")
> Traceback (most recent call last):
> File "<input>", line 1, in <module>
> File "......./PIL/Image.py", line 1916, in open
> raise IOError("cannot identify image file")
> IOError: cannot identify image file
> >>> Image.VERSION
> '1.1.6'
> }}}
>
> Since I ran into this a couple times,
> I was just wondering if this could be fixed ?
>
> Thanks for PIL,
> Sebastian Haase
>
It appears that in Image.py
there are two functions named preinit() and init().
While preinit() seems harmless ,
I found that init() calls
__import__(f, globals(), locals(), [])
with f being every files found ending in "ImagePlugin.py" (without the '.py')
I guess that these calls are supposed to fill in the dictionaries
OPEN, SAVE and ID (and more).
But __import__ does nothing when called the second time for a given
file (import is no reload).
So they stay empty.
Any idea ho to fix this ?
How about changing these lines
_initialized = 0
ID = []
OPEN = {}
MIME = {}
SAVE = {}
EXTENSION = {}
into
try:
_initialied # check if we are imported and not reloaded
except:
_initialized = 0
ID = []
OPEN = {}
MIME = {}
SAVE = {}
EXTENSION = {}
Cheers,
Sebastian Haase
More information about the Image-SIG
mailing list