frakman1 / lifx-lan-gui

LIFX LAN GUI Controller using appJar
MIT License
21 stars 5 forks source link

"OSError: cannot identify image file" during desktop following #4

Closed mclarkk closed 6 years ago

mclarkk commented 6 years ago

Was running the desktop-following in the background at work (so fun!), and I got the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "lights.py", line 685, in followDesktop
    image = ImageGrab.grab(bbox=box)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PIL/ImageGrab.py", line 37, in grab
    im = Image.open(filepath)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PIL/Image.py", line 2585, in open
    % (filename if filename else fp))
OSError: cannot identify image file '/var/folders/_j/jl71c2nx7m7cp5mgvry1rsgm0000gn/T/tmp2u7rek0l.png'
frakman1 commented 6 years ago

Hmm, looks like it might be a transient PIL/pillow error. Try changing line 686:

image = ImageGrab.grab(bbox=box)

to:

try:
     # take a screenshot
     image = ImageGrab.grab(bbox=box)
except Exception as e:
    print ("Ignoring error:", str(e))

and see if it recovers. Maybe there is a file descriptor that isn't getting freed in time.

frakman1 commented 6 years ago

I can confirm that I ran into this problem too. Adding the above code 'fixed' it haha

frakman1 commented 6 years ago

Addressed in commit: https://github.com/frakman1/lifx-lan-gui/commit/f6ce3900297afdf3369facb249310c0d4f57f5ff