Re: [Oiio-dev] Python Oiio don't release image

2018-04-12 Thread Larry Gritz
This gives me an idea for how to make this easier on the next person to come 
across it: I will rig it so that ImageBuf.write() will automatically invalidate 
the file in the ImageCache.

-- lg


> On Apr 12, 2018, at 4:53 AM, Stéphane Bertrand  wrote:
> 
> Thanks for yours helpfulls answers
> 
> Will: in fact, i can convert without delete source image, but isn't my 
> objectif.
> I've 17To of datas for my left eyes, i need the same for my right eyes, and 
> i've only .. 20To
> I'm not fan ( and a little stress) to work directely on rendering source 
> pictures, but i don"t have choice (mistake in rendering parameters )
> 
> Larry have THE solution, thx.
> in python, i can't directely  instantiated from python :
> oiio.ImageCache().invalidate (DIR_PATH+IN_FILE) return  "RuntimeError: This 
> class cannot be instantiated from Python"
> 
> but if i declare it before on startup :
> IMG_CACHE = oiio.ImageCache.create(True)
> and
> IMG_CACHE.invalidate(in_file)
> 
> the file is release and i can delete it ( HAPPY)
> 
> thx a lot, i can run my script this weekend and win free space
> 
> Stephane
> 
> 
> 
> 2018-04-11 18:44 GMT+02:00 Larry Gritz  >:
> Where does the error occur? On the call to rename?
> 
> I think that what's happening is that your ImageBuf is backed by an 
> ImageCache, which is holding the file open. That's my current hypothesis 
> anyway.
> 
> I have two suggestions, either one might work:
> 
> 1. Read the file explicitly, and use the 'force' parameter to read it fully 
> without being backed by an ImageCache.
> 
> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
> img.read (force=True)
> 
> 2. Tell the ImageCache to close and release the file by invalidating it:
> 
> write_image(img, DIR_PATH+out_file)
> oiio.ImageCache().invalidate (DIR_PATH+IN_FILE)
> 
> (Note: the default ImageCache() constructor will retrieve the "shared" one.)
> 
> 
> 
>> On Apr 11, 2018, at 7:39 AM, Stéphane Bertrand > > wrote:
>> 
>> hi all,
>> 
>> i've this simple script, inpire by snippet in the docs :
>> 
>> import os
>> import OpenImageIO as oiio
>> 
>> 
>> DIR_PATH = r"D:\Seq02\Scn01\Shot01\Left\pass\Decor\\"
>> IN_FILE = "Seq02_Scn01_Shot01_Decor_.exr"
>> 
>> 
>> ext = IN_FILE.rfind(".")
>> out_file = IN_FILE[:ext]+ ".tmp" + IN_FILE[ext:]
>> 
>> 
>> def write_image (image, filename, format=oiio.UNKNOWN) :
>>  if not image.has_error :
>>  image.set_write_format (format)
>>  image.write (filename)
>>  if image.has_error :
>>  print("Error writing", filename, ":", image.geterror())
>> 
>> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
>> img.specmod().attribute("compression", "dwaa")
>> write_image(img, DIR_PATH+out_file)
>> 
>> os.remove(DIR_PATH+IN_FILE)
>> os.rename(DIR_PATH+out_file, DIR_PATH+IN_FILE)
>> 
>> it's a simple script for inplace convert with dwa compression a EXR file
>> but i've a PermissionError, my own process have hands on my file
>> i'll try to add 
>> img.reset(oiio.ImageSpec())
>> for free my image
>> but not
>> 
>> thx for your help
>> Stéphane
>> 
>> 
>> ___
>> Oiio-dev mailing list
>> Oiio-dev@lists.openimageio.org 
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
>> 
> 
> --
> Larry Gritz
> l...@larrygritz.com 
> 
> 
> 
> 
> 
> ___
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org 
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
> 
> 
> 
> ___
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
l...@larrygritz.com




___
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org


Re: [Oiio-dev] Python Oiio don't release image

2018-04-12 Thread Stéphane Bertrand
Thanks for yours helpfulls answers

Will: in fact, i can convert without delete source image, but isn't my
objectif.
I've 17To of datas for my left eyes, i need the same for my right eyes, and
i've only .. 20To
I'm not fan ( and a little stress) to work directely on rendering source
pictures, but i don"t have choice (mistake in rendering parameters )

Larry have THE solution, thx.
in python, i can't directely  instantiated from python :
oiio.ImageCache().invalidate (DIR_PATH+IN_FILE) return  "RuntimeError: This
class cannot be instantiated from Python"

but if i declare it before on startup :
IMG_CACHE = oiio.ImageCache.create(True)
and
IMG_CACHE.invalidate(in_file)

the file is release and i can delete it ( HAPPY)

thx a lot, i can run my script this weekend and win free space

Stephane



2018-04-11 18:44 GMT+02:00 Larry Gritz :

> Where does the error occur? On the call to rename?
>
> I think that what's happening is that your ImageBuf is backed by an
> ImageCache, which is holding the file open. That's my current hypothesis
> anyway.
>
> I have two suggestions, either one might work:
>
> 1. Read the file explicitly, and use the 'force' parameter to read it
> fully without being backed by an ImageCache.
>
> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
> img.read (force=True)
>
> 2. Tell the ImageCache to close and release the file by invalidating it:
>
> write_image(img, DIR_PATH+out_file)
> oiio.ImageCache().invalidate (DIR_PATH+IN_FILE)
>
> (Note: the default ImageCache() constructor will retrieve the "shared"
> one.)
>
>
>
> On Apr 11, 2018, at 7:39 AM, Stéphane Bertrand 
> wrote:
>
> hi all,
>
> i've this simple script, inpire by snippet in the docs :
>
> import os
> import OpenImageIO as oiio
>
>
> DIR_PATH = r"D:\Seq02\Scn01\Shot01\Left\pass\Decor\\"
> IN_FILE = "Seq02_Scn01_Shot01_Decor_.exr"
>
>
> ext = IN_FILE.rfind(".")
> out_file = IN_FILE[:ext]+ ".tmp" + IN_FILE[ext:]
>
>
> def write_image (image, filename, format=oiio.UNKNOWN) :
> if not image.has_error :
> image.set_write_format (format)
> image.write (filename)
> if image.has_error :
> print("Error writing", filename, ":", image.geterror())
>
> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
> img.specmod().attribute("compression", "dwaa")
> write_image(img, DIR_PATH+out_file)
>
> os.remove(DIR_PATH+IN_FILE)
> os.rename(DIR_PATH+out_file, DIR_PATH+IN_FILE)
>
> it's a simple script for inplace convert with dwa compression a EXR file
> but i've a PermissionError, my own process have hands on my file
> i'll try to add
> img.reset(oiio.ImageSpec())
> for free my image
> but not
>
> thx for your help
> Stéphane
>
>
> ___
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>
>
> --
> Larry Gritz
> l...@larrygritz.com
>
>
>
>
>
> ___
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>
>
___
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org


Re: [Oiio-dev] Python Oiio don't release image

2018-04-11 Thread Larry Gritz
Where does the error occur? On the call to rename?

I think that what's happening is that your ImageBuf is backed by an ImageCache, 
which is holding the file open. That's my current hypothesis anyway.

I have two suggestions, either one might work:

1. Read the file explicitly, and use the 'force' parameter to read it fully 
without being backed by an ImageCache.

img = oiio.ImageBuf(DIR_PATH+IN_FILE)
img.read (force=True)

2. Tell the ImageCache to close and release the file by invalidating it:

write_image(img, DIR_PATH+out_file)
oiio.ImageCache().invalidate (DIR_PATH+IN_FILE)

(Note: the default ImageCache() constructor will retrieve the "shared" one.)



> On Apr 11, 2018, at 7:39 AM, Stéphane Bertrand  wrote:
> 
> hi all,
> 
> i've this simple script, inpire by snippet in the docs :
> 
> import os
> import OpenImageIO as oiio
> 
> 
> DIR_PATH = r"D:\Seq02\Scn01\Shot01\Left\pass\Decor\\"
> IN_FILE = "Seq02_Scn01_Shot01_Decor_.exr"
> 
> 
> ext = IN_FILE.rfind(".")
> out_file = IN_FILE[:ext]+ ".tmp" + IN_FILE[ext:]
> 
> 
> def write_image (image, filename, format=oiio.UNKNOWN) :
>   if not image.has_error :
>   image.set_write_format (format)
>   image.write (filename)
>   if image.has_error :
>   print("Error writing", filename, ":", image.geterror())
> 
> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
> img.specmod().attribute("compression", "dwaa")
> write_image(img, DIR_PATH+out_file)
> 
> os.remove(DIR_PATH+IN_FILE)
> os.rename(DIR_PATH+out_file, DIR_PATH+IN_FILE)
> 
> it's a simple script for inplace convert with dwa compression a EXR file
> but i've a PermissionError, my own process have hands on my file
> i'll try to add 
> img.reset(oiio.ImageSpec())
> for free my image
> but not
> 
> thx for your help
> Stéphane
> 
> 
> ___
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
l...@larrygritz.com




___
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org


Re: [Oiio-dev] Python Oiio don't release image

2018-04-11 Thread Will Rosecrans
Can you rename the source file first, then open it, then try to write the
result to the original filename?

Then you can del all the OIIO Python objects and delete the original file
after everything is done.  (Or add an option to leave the source file as a
backup for the user.)

On Wed, Apr 11, 2018, 8:12 AM Stéphane Bertrand 
wrote:

> thx for your answer
>
> you right, i'm on Windows
> i'm agree with you, my code is ugly with file path, it's just a crash code
> simplification for my post
>
> the problem is with os.remove on original image
>
> if i launch my script in interactive mode, without the last two lines (
> os.remove and os.rename)
> python -i compress_dwaa.py
> so my python interprete still alive
>
> i can't delete by hand my file because : "file is open by python.exe
> process"
>
>
> 2018-04-11 17:01 GMT+02:00 Scott Wilson :
>
>> Not sure if this will help you out, but out of curiosity, have you tried
>> only deleting or renaming the file? From what I remember when I used oiio
>> on Windows, I was able to do delete/rename.
>>
>> Also, here's some general Python tips:
>> - Use os.splitext(path) to get everything leading up to the extension,
>> and the .ext. For example "my file.ext" becomes ("my file", ".ext")
>> - Use os.path.join(pathroot, filename) when joining paths, because it
>> handled when the path root ends with a '/' or not.
>> - Strong formatting is generally preferred to strong concatenation
>> because it is usually faster, and can be more readable. For example:
>> outfile = "{}.tmp{}".format(filename, ext)
>>
>> On Wed, Apr 11, 2018, 7:39 AM Stéphane Bertrand, 
>> wrote:
>>
>>> hi all,
>>>
>>> i've this simple script, inpire by snippet in the docs :
>>>
>>> import os
>>> import OpenImageIO as oiio
>>>
>>>
>>> DIR_PATH = r"D:\Seq02\Scn01\Shot01\Left\pass\Decor\\"
>>> IN_FILE = "Seq02_Scn01_Shot01_Decor_.exr"
>>>
>>>
>>> ext = IN_FILE.rfind(".")
>>> out_file = IN_FILE[:ext]+ ".tmp" + IN_FILE[ext:]
>>>
>>>
>>> def write_image (image, filename, format=oiio.UNKNOWN) :
>>> if not image.has_error :
>>> image.set_write_format (format)
>>> image.write (filename)
>>> if image.has_error :
>>> print("Error writing", filename, ":", image.geterror())
>>>
>>> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
>>> img.specmod().attribute("compression", "dwaa")
>>> write_image(img, DIR_PATH+out_file)
>>>
>>> os.remove(DIR_PATH+IN_FILE)
>>> os.rename(DIR_PATH+out_file, DIR_PATH+IN_FILE)
>>>
>>> it's a simple script for inplace convert with dwa compression a EXR file
>>> but i've a PermissionError, my own process have hands on my file
>>> i'll try to add
>>> img.reset(oiio.ImageSpec())
>>> for free my image
>>> but not
>>>
>>> thx for your help
>>> Stéphane
>>>
>>>
>>> ___
>>> Oiio-dev mailing list
>>> Oiio-dev@lists.openimageio.org
>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>>
>>
>> ___
>> Oiio-dev mailing list
>> Oiio-dev@lists.openimageio.org
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>
>>
> ___
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>
___
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org


Re: [Oiio-dev] Python Oiio don't release image

2018-04-11 Thread Stéphane Bertrand
Python binding launch the cache system ?
So the cache have handle on my file ?

2018-04-11 17:12 GMT+02:00 Stéphane Bertrand :

> thx for your answer
>
> you right, i'm on Windows
> i'm agree with you, my code is ugly with file path, it's just a crash code
> simplification for my post
>
> the problem is with os.remove on original image
>
> if i launch my script in interactive mode, without the last two lines (
> os.remove and os.rename)
> python -i compress_dwaa.py
> so my python interprete still alive
>
> i can't delete by hand my file because : "file is open by python.exe
> process"
>
>
> 2018-04-11 17:01 GMT+02:00 Scott Wilson :
>
>> Not sure if this will help you out, but out of curiosity, have you tried
>> only deleting or renaming the file? From what I remember when I used oiio
>> on Windows, I was able to do delete/rename.
>>
>> Also, here's some general Python tips:
>> - Use os.splitext(path) to get everything leading up to the extension,
>> and the .ext. For example "my file.ext" becomes ("my file", ".ext")
>> - Use os.path.join(pathroot, filename) when joining paths, because it
>> handled when the path root ends with a '/' or not.
>> - Strong formatting is generally preferred to strong concatenation
>> because it is usually faster, and can be more readable. For example:
>> outfile = "{}.tmp{}".format(filename, ext)
>>
>> On Wed, Apr 11, 2018, 7:39 AM Stéphane Bertrand, 
>> wrote:
>>
>>> hi all,
>>>
>>> i've this simple script, inpire by snippet in the docs :
>>>
>>> import os
>>> import OpenImageIO as oiio
>>>
>>>
>>> DIR_PATH = r"D:\Seq02\Scn01\Shot01\Left\pass\Decor\\"
>>> IN_FILE = "Seq02_Scn01_Shot01_Decor_.exr"
>>>
>>>
>>> ext = IN_FILE.rfind(".")
>>> out_file = IN_FILE[:ext]+ ".tmp" + IN_FILE[ext:]
>>>
>>>
>>> def write_image (image, filename, format=oiio.UNKNOWN) :
>>> if not image.has_error :
>>> image.set_write_format (format)
>>> image.write (filename)
>>> if image.has_error :
>>> print("Error writing", filename, ":", image.geterror())
>>>
>>> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
>>> img.specmod().attribute("compression", "dwaa")
>>> write_image(img, DIR_PATH+out_file)
>>>
>>> os.remove(DIR_PATH+IN_FILE)
>>> os.rename(DIR_PATH+out_file, DIR_PATH+IN_FILE)
>>>
>>> it's a simple script for inplace convert with dwa compression a EXR file
>>> but i've a PermissionError, my own process have hands on my file
>>> i'll try to add
>>> img.reset(oiio.ImageSpec())
>>> for free my image
>>> but not
>>>
>>> thx for your help
>>> Stéphane
>>>
>>>
>>> ___
>>> Oiio-dev mailing list
>>> Oiio-dev@lists.openimageio.org
>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>>
>>
>> ___
>> Oiio-dev mailing list
>> Oiio-dev@lists.openimageio.org
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>
>>
>
___
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org


Re: [Oiio-dev] Python Oiio don't release image

2018-04-11 Thread Stéphane Bertrand
thx for your answer

you right, i'm on Windows
i'm agree with you, my code is ugly with file path, it's just a crash code
simplification for my post

the problem is with os.remove on original image

if i launch my script in interactive mode, without the last two lines (
os.remove and os.rename)
python -i compress_dwaa.py
so my python interprete still alive

i can't delete by hand my file because : "file is open by python.exe
process"


2018-04-11 17:01 GMT+02:00 Scott Wilson :

> Not sure if this will help you out, but out of curiosity, have you tried
> only deleting or renaming the file? From what I remember when I used oiio
> on Windows, I was able to do delete/rename.
>
> Also, here's some general Python tips:
> - Use os.splitext(path) to get everything leading up to the extension, and
> the .ext. For example "my file.ext" becomes ("my file", ".ext")
> - Use os.path.join(pathroot, filename) when joining paths, because it
> handled when the path root ends with a '/' or not.
> - Strong formatting is generally preferred to strong concatenation because
> it is usually faster, and can be more readable. For example: outfile =
> "{}.tmp{}".format(filename, ext)
>
> On Wed, Apr 11, 2018, 7:39 AM Stéphane Bertrand, 
> wrote:
>
>> hi all,
>>
>> i've this simple script, inpire by snippet in the docs :
>>
>> import os
>> import OpenImageIO as oiio
>>
>>
>> DIR_PATH = r"D:\Seq02\Scn01\Shot01\Left\pass\Decor\\"
>> IN_FILE = "Seq02_Scn01_Shot01_Decor_.exr"
>>
>>
>> ext = IN_FILE.rfind(".")
>> out_file = IN_FILE[:ext]+ ".tmp" + IN_FILE[ext:]
>>
>>
>> def write_image (image, filename, format=oiio.UNKNOWN) :
>> if not image.has_error :
>> image.set_write_format (format)
>> image.write (filename)
>> if image.has_error :
>> print("Error writing", filename, ":", image.geterror())
>>
>> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
>> img.specmod().attribute("compression", "dwaa")
>> write_image(img, DIR_PATH+out_file)
>>
>> os.remove(DIR_PATH+IN_FILE)
>> os.rename(DIR_PATH+out_file, DIR_PATH+IN_FILE)
>>
>> it's a simple script for inplace convert with dwa compression a EXR file
>> but i've a PermissionError, my own process have hands on my file
>> i'll try to add
>> img.reset(oiio.ImageSpec())
>> for free my image
>> but not
>>
>> thx for your help
>> Stéphane
>>
>>
>> ___
>> Oiio-dev mailing list
>> Oiio-dev@lists.openimageio.org
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>
>
> ___
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>
>
___
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org