python-pillow / Sane

Python interface to the SANE scanner and frame grabber
Other
55 stars 19 forks source link

_SaneIterator destructor calls self.device.cancel() #50

Closed PhilippWoelfel closed 3 years ago

PhilippWoelfel commented 5 years ago

The destructor of a _SaneIterator object calls device.cancel(), which may lead to exceptions if the user has already closed the device.

Consider the following code:

sane.init()
dev =  sane.open("device")
iterator = dev.multi_scan()
while True:
    try:
        image = iterator.next()
    except:
        break
dev.cancel()
dev.close()
sane.exit()

This will cause an exception when the garbage collector destroys iterator. The only reasonable work-around I found is to manually destroy the _SaneIterator object before closing the device, but having to do that is not what I would expect at all.

manisandro commented 3 years ago

Should be addressed by 238d61f .