You have to wait until IO is ready. In Unix, we accomplish this with fcntl and the default signal SIGIO, I am not sure how you would do this in Windows.
On Mon, May 11, 2009 at 9:51 AM, justind <justin.don...@gmail.com> wrote: > Hello, > > I'm using http://code.activestate.com/recipes/156178/ to watch a > folder in windows. It's working perfectly, but sometimes when I try to > open the file immediately after receiving the event, it's not ready to > be opened--if I try to open it with PIL I get "IOError: cannot > identify image file" and if I try it with a text file, it's empty. > This doesn't happen all the time, just occasionally. I think the > problem is that the file isn't completely written because if I make > the script sleep for a second, it works every time. But that doesn't > seem very elegant or robust. > > What's the proper way to make sure the file is ready to be read? > > I'm just passing the file names from the above recipe to a function. > Something like > > def handler(files): > for file in files: > im = Image.open(file) > > Thanks > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list