Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

I/O error on sane.SaneDev.snap() #447

Closed
barronmo opened this Issue Dec 13, 2013 · 36 comments

Comments

Projects
None yet
3 participants

Arch Linux updated 2 weeks ago
HP OfficeJet 6700 Premium All-in-One
Pillow 2.2.1
Python 2.7.5

import sane
sane.init()
d = sane.get_devices()
s = sane.open(d[0][0])
image = s.scan()
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/sane.py", line 247, in scan
return self.snap()
File "/usr/lib/python2.7/site-packages/sane.py", line 242, in snap
self.dev.snap( im.im.id, no_cancel )
_sane.error: Error during device I/O

Thanks for any help.

Forgot to mention that scanner works OK using scanimage from command line.

Member

manisandro commented Dec 19, 2013

Could you run python through gdb, break on _sane.c:431 (see https://github.com/python-imaging/Pillow/blob/master/Sane/_sane.c), then step through the code until a PySane_Error error is returned and report where the code is failing? Make sure you have the binaries compiled with debugging symbols resp. have corresponding debuginfo packages installed.

Owner

aclark4life commented Jan 1, 2014

Now targeting 2.4.0

Debugging is new to me; I think I've run into a problem. Based on advice from https://wiki.python.org/moin/DebuggingWithGdb I need python debugging extensions. I can't seem to find any in the Arch repositories. I tried running the program through gbd without them but I'm getting the same error message. Any ideas?

Thanks.

Member

manisandro commented Jan 17, 2014

Apparently [1] on Arch there are no readily available debuginfo packages.
You could either try following those instructions, or debug the issue using a Live CD of a distro which provides debuginfo packages, such as Fedora. On Fedora, after booting the Live CD, you would

$ sudo yum install python-pillow-sane gdb
$ sudo debuginfo-install python-pillow-sane
$ gdb python
(gdb) break SaneDev_start
Function "SaneDev_start" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (SaneDev_start) pending.
(gdb) break SaneDev_snap
Function "SaneDev_snap" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (SaneDev_snap) pending.
(gdb) run
# In the python console which now appears, type the commands you posted above. You should then hit a breakpoint.
Breakpoint 1, SaneDev_start (self=0x7ffff7f53138, args=()) at _sane.c:153
153     {
# Now, press n (i.e. next) to walk through the function statement by statement. To step into a function at a statement, press s. To continue until the end of a function, type finish. Also see [2] for more info,
(gdb) n
156       if (!PyArg_ParseTuple(args, ""))
# etc

Walking thorugh the function, look out for PySane_Error and PyErr_SetString statements. If the function returns on one of these statements, that is where the code is failing: please post back here where.

A note on breakpoints: you might want to break on other functions / lines in the code also. Look at [3] and break accordingly on function names, i.e.

(gdb) break SaneDev_snap

or file+line numbers, i.e.

(gdb) break _sane.c:433

Hope this helps.

[1] https://wiki.archlinux.org/index.php/Debug_-_Getting_Traces#Compilation_settings
[2] https://sourceware.org/gdb/onlinedocs/gdb/Continuing-and-Stepping.html
[3] https://github.com/python-imaging/Pillow/blob/master/Sane/_sane.c

I thought I would try the python debugger pdb first. The instructions in [1] confused me and I don't have a cd big enough to make a Fedora disk (and unfortunately my desktop bios won't let me boot from usb). I have had some difficulty setting a break point but I think I got something useful by using 'break s._sane.c:431'. Here is most of what happened after the break:

-> def scan(self):
(Pdb) l
240                 raise ValueError('got unknown "mode" from self.get_parameters()')
241             im=Image.new(format, (xsize,ysize))
242         self.dev.snap( im.im.id, no_cancel )
243         return im
244     
245  ->     def scan(self):
246             self.start()
247             return self.snap()
248     
249         def multi_scan(self):
250             return _SaneIterator(self)
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(246)scan()
-> self.start()
(Pdb) 
--Call--
> /usr/lib/python2.7/site-packages/sane.py(223)start()
-> def start(self):
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(225)start()
-> return self.dev.start()
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/sane.py(225)start()->None
-> return self.dev.start()
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(247)scan()
-> return self.snap()
(Pdb) s
--Call--
> /usr/lib/python2.7/site-packages/sane.py(231)snap()
-> def snap(self, no_cancel=0):
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(234)snap()
-> (xsize, ysize), depth, bytes_per_line) = self.get_parameters()
(Pdb) s
--Call--
> /usr/lib/python2.7/site-packages/sane.py(207)get_parameters()
-> def get_parameters(self):
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(217)get_parameters()
-> return self.dev.get_parameters()
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/sane.py(217)get_parameters()->('gray', 1, (637, 877), 1, 80)
-> return self.dev.get_parameters()
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(235)snap()
-> if mode in ['gray', 'red', 'green', 'blue']:
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(236)snap()
-> format = 'L'
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(241)snap()
-> im=Image.new(format, (xsize,ysize))
(Pdb) s
--Call--
> /usr/lib/python2.7/site-packages/PIL/Image.py(1746)new()
-> def new(mode, size, color=0):
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(1761)new()
-> if color is None:
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(1765)new()
-> if isStringType(color):
(Pdb) s
--Call--
> /usr/lib/python2.7/site-packages/PIL/_util.py(4)isStringType()
-> def isStringType(t):
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/_util.py(5)isStringType()
-> return isinstance(t, basestring)
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/PIL/_util.py(5)isStringType()->False
-> return isinstance(t, basestring)
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(1771)new()
-> return Image()._new(core.fill(mode, size, color))
(Pdb) s
--Call--
> /usr/lib/python2.7/site-packages/PIL/Image.py(457)__init__()
-> def __init__(self):
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(460)__init__()
-> self.im = None
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(461)__init__()
-> self.mode = ""
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(462)__init__()
-> self.size = (0, 0)
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(463)__init__()
-> self.palette = None
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(464)__init__()
-> self.info = {}
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(465)__init__()
-> self.category = NORMAL
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(466)__init__()
-> self.readonly = 0
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/PIL/Image.py(466)__init__()->None
-> self.readonly = 0
(Pdb) s
--Call--
> /usr/lib/python2.7/site-packages/PIL/Image.py(468)_new()
-> def _new(self, im):
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(469)_new()
-> new = Image()
(Pdb) s
--Call--
> /usr/lib/python2.7/site-packages/PIL/Image.py(457)__init__()
-> def __init__(self):
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(460)__init__()
-> self.im = None
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(461)__init__()
-> self.mode = ""
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(462)__init__()
-> self.size = (0, 0)
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(463)__init__()
-> self.palette = None
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(464)__init__()
-> self.info = {}
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(465)__init__()
-> self.category = NORMAL
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(466)__init__()
-> self.readonly = 0
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/PIL/Image.py(466)__init__()->None
-> self.readonly = 0
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(470)_new()
-> new.im = im
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(471)_new()
-> new.mode = im.mode
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(472)_new()
-> new.size = im.size
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(473)_new()
-> new.palette = self.palette
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(474)_new()
-> if im.mode == "P":
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(477)_new()
-> try:
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(478)_new()
-> new.info = self.info.copy()
(Pdb) s
> /usr/lib/python2.7/site-packages/PIL/Image.py(484)_new()
-> return new
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/PIL/Image.py(484)_new()-><PIL.Image.Im... at 0x2764A28>
-> return new
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/PIL/Image.py(1771)new()-><PIL.Image.Im... at 0x2764A28>
-> return Image()._new(core.fill(mode, size, color))
(Pdb) s
> /usr/lib/python2.7/site-packages/sane.py(242)snap()
-> self.dev.snap( im.im.id, no_cancel )
(Pdb) s
error: 'Error during device I/O'
> /usr/lib/python2.7/site-packages/sane.py(242)snap()
-> self.dev.snap( im.im.id, no_cancel )
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/sane.py(242)snap()->None
-> self.dev.snap( im.im.id, no_cancel )
(Pdb) s
error: 'Error during device I/O'
> /usr/lib/python2.7/site-packages/sane.py(247)scan()
-> return self.snap()
(Pdb) s
--Return--
> /usr/lib/python2.7/site-packages/sane.py(247)scan()->None
-> return self.snap()
(Pdb) s
error: 'Error during device I/O'
> /home/sl/Desktop/scannerTest.py(7)<module>()
-> image = s.scan()
(Pdb) s
--Return--
> /home/sl/Desktop/scannerTest.py(7)<module>()->None
-> image = s.scan()
(Pdb) 
Member

manisandro commented Jan 20, 2014

Unfortunately this only tells us that the error occurs in SaneDev.snap(). What you could also do is build your own python-pillow and install with prefix /usr/local (or anywhere else outside of the system prefix for the matter), i.e. download the pillow source archive and then

python setup.py install --prefix=/usr/local

Then, add /usr/local/lib/python2.7/site-packages in front of your PYTHONPATH when starting gdb. For instance:

PYTHONPATH=/usr/local/lib/python2.7/site-packages gdb python

Then python should pick up the modules in /usr/local/lib/python2.7/site-packages when importing sane. Just make sure you are compiling pillow with debug flags (which should actually be default) and that the binaries are not stripped afterwards.

How do I compile pillow with debug flags? Wouldn't the compiling be handled by the setup.py file? I couldn't find any mention of DEBUG flags in that file or setup.cfg or Makefile. I also don't know what 'stripping' refers to related to the binaries. How do I prevent it?

I think I made some progress. [1] mentioned changing /etc/makepkg.conf options to allow for debugging and stop stripping. I reinstalled python2-pillow with the adjusted makepkg.conf file. Will try gdb again.

Couldn't get any different output from gdb, but tried pdb and got the following:

Traceback (most recent call last):
  File "scannerTest.py", line 7, in <module>
    image = s.scan()
  File "/usr/lib/python2.7/site-packages/sane.py", line 247, in scan
    return self.snap()
  File "/usr/lib/python2.7/site-packages/sane.py", line 242, in snap
    self.dev.snap( im.im.id, no_cancel )
_sane.error: Error during device I/O
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x7f9ebff365f0> ignored

Here's scannerTest.py:

import pdb, sane

sane.init()
d = sane.get_devices()
s = sane.open(d[0][0])
pdb.set_trace()
image = s.scan()
image.save('/home/sl/Downloads/test4.pdf')
s.close()
sane.exit()

I think the 'path' mentioned in the above error may refer the line after the error occurs.

Can't seem to get the break points to work in gdb like they do in pdb.

Tried collecting a backtrace log from gdb:

Starting program: /usr/bin/python2 --verbose
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[Inferior 1 (process 3705) exited with code 02]
Starting program: /usr/bin/python2 --verbose
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[Inferior 1 (process 3710) exited with code 02]
Starting program: /usr/bin/python2 --verbose
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7f$
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[Inferior 1 (process 3711) exited with code 02]
Starting program: /usr/bin/python2
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffef793700 (LWP 3720)]
[Thread 0x7fffef793700 (LWP 3720) exited]
[New Thread 0x7fffef793700 (LWP 3722)]
[New Thread 0x7fffe55f2700 (LWP 3723)]
[New Thread 0x7fffe4df1700 (LWP 3741)]
[Thread 0x7fffe4df1700 (LWP 3741) exited]
[New Thread 0x7fffe4df1700 (LWP 3742)]
[Thread 0x7fffe4df1700 (LWP 3742) exited]
[New Thread 0x7fffe4df1700 (LWP 3743)]
[Thread 0x7fffe4df1700 (LWP 3743) exited]
[New Thread 0x7fffdffff700 (LWP 3744)]
[New Thread 0x7fffe4df1700 (LWP 3746)]
[Thread 0x7fffdffff700 (LWP 3744) exited]
[Thread 0x7fffe4df1700 (LWP 3746) exited]
[New Thread 0x7fffe4df1700 (LWP 3747)]
[Thread 0x7fffe4df1700 (LWP 3747) exited]
[New Thread 0x7fffe4df1700 (LWP 3748)]
[Thread 0x7fffe4df1700 (LWP 3748) exited]
[New Thread 0x7fffe4df1700 (LWP 3749)]
[Thread 0x7fffe4df1700 (LWP 3749) exited]
[New Thread 0x7fffe4df1700 (LWP 3750)]
[Thread 0x7fffe4df1700 (LWP 3750) exited]
[New Thread 0x7fffe4df1700 (LWP 3751)]
[Thread 0x7fffe4df1700 (LWP 3751) exited]
[New Thread 0x7fffe4df1700 (LWP 3752)]
[Thread 0x7fffe4df1700 (LWP 3752) exited]
[New Thread 0x7fffe4df1700 (LWP 3753)]
[Thread 0x7fffe4df1700 (LWP 3753) exited]
[New Thread 0x7fffe4df1700 (LWP 3754)]
[Thread 0x7fffe4df1700 (LWP 3754) exited]
[New Thread 0x7fffe4df1700 (LWP 3755)]
[Thread 0x7fffe4df1700 (LWP 3755) exited]
[New Thread 0x7fffe4df1700 (LWP 3756)]
[Thread 0x7fffe4df1700 (LWP 3756) exited]
[New Thread 0x7fffe4df1700 (LWP 3757)]
[Thread 0x7fffe4df1700 (LWP 3757) exited]
[New Thread 0x7fffdffff700 (LWP 3758)]
[Thread 0x7fffdffff700 (LWP 3758) exited]
[Thread 0x7fffef793700 (LWP 3722) exited]
[Thread 0x7ffff7fc6700 (LWP 3715) exited]
[Inferior 1 (process 3715) exited normally]
No stack.
Member

manisandro commented Jan 20, 2014

pdb again is telling us that the error occurs in SaneDev.snap(), and the exception is because s.scan() returns None, consequently image.save() fails since image is None.

Here are some (actually tested) and complete instructions for installing a local copy and debug it:

# install tk-devel libjpeg-devel zlib-devel freetype-devel lcms2-devel sane-backends-devel libwebp-devel python2-devel python-setuptools tkinter
# Note: the package names above are the ones for fedora, you will need to search the corresponding ones for arch. They should actually be named very similarly, so should not be hard.
# Create a folder where to install pillow to
mkdir $HOME/pillowroot
# Download the pillow source archive, extract and cd into the folder
cd /path/to/python-pillow-source
# Compile pillow and the sane module 
CFLAGS="-g" python setup.py install --root=$HOME/pillowroot
cd Sane
CFLAGS="-g" python setup.py install --root=$HOME/pillowroot
# Run gdb
PYTHONPATH=$HOME/pillowroot/usr/lib/python2.7/site-packages/ gdb python
(gdb) break SaneDev_snap
Function "SaneDev_snap" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (SaneDev_snap) pending.
(gdb) run
>>> import sane
>>> print sane.__file__
# This should output '$HOME/pillowroot/usr/lib/python2.7/site-packages/sane.pyc'
# where $HOME is the path to your home folder
>>> sane.init()
(16777240, 1, 0, 24)
>>> devices=sane.get_devices()
[New Thread 0x7fffec72b700 (LWP 7141)]
>>> dev=sane.open(devices[0][0])
>>> dev.snap()

Breakpoint 1, SaneDev_snap (self=0x7ffff7f52138, args=(7670192, 0)) at _sane.c:432
432     {

Ran into the lack of python-devel problem in Arch, but I managed to get some DVR discs and make a Fedora .iso. It appears I'm stuck in a loop after SaneDev_snap:

Breakpoint 2, SaneDev_snap (self=0x7ffff7f62138, args=(8560176, 0))
    at _sane.c:432
432 {
(gdb) n
453   if (!PyArg_ParseTuple(args, "l|O", &L, &pyNoCancel))
(gdb) n
432 {
(gdb) n
453   if (!PyArg_ParseTuple(args, "l|O", &L, &pyNoCancel))
(gdb) n
448   PyObject *pyNoCancel = NULL;
(gdb) n
453   if (!PyArg_ParseTuple(args, "l|O", &L, &pyNoCancel))
(gdb) n
455   if (self->h==NULL)
(gdb) n
462   if (pyNoCancel)
(gdb) n
460   im=(Imaging)L;
(gdb) n
449   int noCancel = 0;
(gdb) n
462   if (pyNoCancel)
(gdb) n
463     noCancel = PyObject_IsTrue(pyNoCancel);
(gdb) n
474   Py_UNBLOCK_THREADS
(gdb) n
475   sane_get_parameters(self->h, &p);
(gdb) n
476   if (p.format == SANE_FRAME_GRAY)
(gdb) n
478       switch (p.depth)
(gdb) n
482             padbytes = p.bytes_per_line - (im->xsize+7)/8;
(gdb) n
481             remain = p.bytes_per_line * im->ysize;
(gdb) n
484             lastlen = len = 0;
(gdb) n
482             padbytes = p.bytes_per_line - (im->xsize+7)/8;
(gdb) n
481             remain = p.bytes_per_line * im->ysize;
(gdb) n
482             padbytes = p.bytes_per_line - (im->xsize+7)/8;
(gdb) n
483             bufpos = 0;
(gdb) n
484             lastlen = len = 0;
(gdb) n
482             padbytes = p.bytes_per_line - (im->xsize+7)/8;
(gdb) n
465   st=SANE_STATUS_GOOD; px=py=0;
(gdb) n
482             padbytes = p.bytes_per_line - (im->xsize+7)/8;
(gdb) n
485             while (st!=SANE_STATUS_EOF && py < im->ysize)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
487                 while (len > 0 && py < im->ysize)
(gdb) n
506                 st=sane_read(self->h, buffer,
(gdb) n
508                 if (st && (st!=SANE_STATUS_EOF))
(gdb) n
514                 bufpos -= lastlen;
(gdb) n
515                 lastlen = len;
(gdb) n
518                 len -= bufpos;
(gdb) n
516                 remain -= len;
(gdb) n
518                 len -= bufpos;
(gdb) n
485             while (st!=SANE_STATUS_EOF && py < im->ysize)
(gdb) n
518                 len -= bufpos;
(gdb) n
485             while (st!=SANE_STATUS_EOF && py < im->ysize)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
487                 while (len > 0 && py < im->ysize)
(gdb) n
490                     j = buffer[bufpos++];
(gdb) n
491                     k = 0x80;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
497                     len--;
(gdb) n
498                     if (px >= im->xsize)
(gdb) n
497                     len--;
(gdb) n
498                     if (px >= im->xsize)
(gdb) n
487                 while (len > 0 && py < im->ysize)
(gdb) n
490                     j = buffer[bufpos++];
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
487                 while (len > 0 && py < im->ysize)
(gdb) n
490                     j = buffer[bufpos++];
(gdb) n
491                     k = 0x80;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
497                     len--;
(gdb) n
498                     if (px >= im->xsize)
(gdb) n
497                     len--;
(gdb) n
498                     if (px >= im->xsize)
(gdb) n
487                 while (len > 0 && py < im->ysize)
(gdb) n
490                     j = buffer[bufpos++];
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
487                 while (len > 0 && py < im->ysize)
(gdb) n
490                     j = buffer[bufpos++];
(gdb) n

It keeps going after this if I keep pressing 'n'.

No error messages so far either.

Member

manisandro commented Jan 21, 2014

First of all, can you reproduce the issue on Fedora (i.e. running normally, without gdb, do you still get the _sane.error: Error during device I/O? If not, the issue could be a sane driver issue and not a pillow one.

As far as the backtrace is concerned: the loop you were stepping through is expected to run quite often since it is reading line per line of your image data. Instead of hitting n 1000 times, you could just place the breakpoints where an error is thrown, i.e. at _sane.c:512 would be one such spot.

Yes, still same error:

492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) c
Continuing.
[New Thread 0x7fffdffe6700 (LWP 2399)]
[Thread 0x7fffdffe6700 (LWP 2399) exited]
[New Thread 0x7fffdf7e5700 (LWP 2400)]
[Thread 0x7fffdf7e5700 (LWP 2400) exited]
Detaching after fork from child process 2401.
Detaching after fork from child process 2403.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/sane.py", line 247, in scan
    return self.snap()
  File "/usr/lib64/python2.7/site-packages/sane.py", line 242, in snap
    self.dev.snap( im.im.id, no_cancel )
_sane.error: Error during device I/O
Member

manisandro commented Jan 21, 2014

Okay, so now try adding breakpoints on all the lines in _sane.c in the function SaneDev_snap which include PySane_Error and see if you can find out where the error is triggered.

Does this help:

Breakpoint 1, SaneDev_snap (self=0x7ffff7f62138, args=<optimized out>)
    at _sane.c:514
514                 bufpos -= lastlen;
Missing separate debuginfos, use: debuginfo-install avahi-libs-0.6.31-21.fc20.x86_64 cups-libs-1.7.0-4.fc20.x86_64 
dbus-libs-1.6.12-1.fc20.x86_64 hplip-libs-3.13.11-4.fc20.x86_64 jbigkit-libs-2.0-9.fc20.x86_64 keyutils-
libs-1.5.8-1.fc20.x86_64 krb5-libs-1.11.3-33.fc20.x86_64 libcom_err-1.42.8-3.fc20.x86_64 libexif-
0.6.21-6.fc20.x86_64 libgcc-4.8.2-1.fc20.x86_64 libgphoto2-2.5.2-5.fc20.x86_64 libieee1284-0.2.11-15.fc20.x86_64 
libjpeg-turbo-1.3.0-1.fc20.x86_64 libsane-hpaio-3.13.11-4.fc20.x86_64 libselinux-2.1.13-19.fc20.x86_64 libtiff-
4.0.3-12.fc20.x86_64 libtool-ltdl-2.4.2-21.fc20.x86_64 libusbx-1.0.16-3.fc20.x86_64 libv4l-1.0.0-1.fc20.x86_64 
ncurses-libs-5.9-12.20130511.fc20.x86_64 net-snmp-libs-5.7.2-15.fc20.x86_64 nss-softokn-freebl-
3.15.2-2.fc20.x86_64 openssl-libs-1.0.1e-30.fc20.x86_64 pcre-8.33-2.fc20.1.x86_64 readline-6.2-8.fc20.x86_64 
systemd-libs-208-9.fc20.x86_64 zlib-1.2.8-3.fc20.x86_64
(gdb) n
515                 lastlen = len;
(gdb) n
518                 len -= bufpos;
(gdb) n
516                 remain -= len;
(gdb) n
518                 len -= bufpos;
(gdb) n
485             while (st!=SANE_STATUS_EOF && py < im->ysize)
(gdb) n
518                 len -= bufpos;
(gdb) n
485             while (st!=SANE_STATUS_EOF && py < im->ysize)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
487                 while (len > 0 && py < im->ysize)
(gdb) n
490                     j = buffer[bufpos++];
(gdb) n
491                     k = 0x80;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
495                         k = k >> 1;
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) n
492                     for (i = 0; i < 8 && px < im->xsize; i++)
(gdb) n
494                         im->image8[py][px++] = (k&j) ? 0 : 0xFF;
(gdb) c
Continuing.

Breakpoint 1, SaneDev_snap (self=0x7ffff7f62138, args=<optimized out>)
    at _sane.c:514
514                 bufpos -= lastlen;
(gdb) c
Continuing.

Breakpoint 1, SaneDev_snap (self=0x7ffff7f62138, args=<optimized out>)
    at _sane.c:514
514                 bufpos -= lastlen;
(gdb) c
Continuing.

Breakpoint 1, SaneDev_snap (self=0x7ffff7f62138, args=<optimized out>)
    at _sane.c:514
514                 bufpos -= lastlen;
(gdb) c
Continuing.

Breakpoint 1, SaneDev_snap (self=0x7ffff7f62138, args=<optimized out>)
    at _sane.c:514
514                 bufpos -= lastlen;
(gdb) c
Continuing.
[New Thread 0x7fffdffe6700 (LWP 2477)]
[Thread 0x7fffdffe6700 (LWP 2477) exited]
[New Thread 0x7fffdf7e5700 (LWP 2478)]
[Thread 0x7fffdf7e5700 (LWP 2478) exited]
Detaching after fork from child process 2479.
Detaching after fork from child process 2481.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/sane.py", line 247, in scan
    return self.snap()
  File "/usr/lib64/python2.7/site-packages/sane.py", line 242, in snap
    self.dev.snap( im.im.id, no_cancel )
_sane.error: Error during device I/O
Member

manisandro commented Jan 21, 2014

I'm afraid not. Actually the easiest is if you set a breakpoint at _sane.c:55, then when you gdb hits the breakpoint, type backtrace and copy here the lines that appear after. From there, we can deduce where the error got triggered.

#0  PySane_Error (st=SANE_STATUS_IO_ERROR) at _sane.c:55
#1  0x00007fffeec2e729 in SaneDev_snap (self=<optimized out>, 
    args=<optimized out>) at _sane.c:948
#2  0x00007ffff7af7c84 in call_function (oparg=<optimized out>, 
    pp_stack=0x7fffffffda60) at /usr/src/debug/Python-2.7.5/Python/ceval.c:4098
#3  PyEval_EvalFrameEx (
    f=f@entry=Frame 0x822390, for file /usr/lib64/python2.7/site-packages/sane.py, line 242, in snap (self=<SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7ffff7ea6a28>, 'tl_y': <Option(index=12, name='tl-y', title='Top-left y', py_name='tl_y', cap=5, con...(truncated), throwflag=throwflag@entry=0)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:2740
#4  0x00007ffff7af929d in PyEval_EvalCodeEx (co=<optimized out>, 
    globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, 
    argcount=argcount@entry=1, kws=0x81ccb8, kwcount=0, defs=0x7ffff7edfae8, 
    defcount=1, closure=closure@entry=0x0)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:3330
#5  0x00007ffff7af794f in fast_function (nk=<optimized out>, na=1, n=1, 
    pp_stack=0x7fffffffdc60, func=<function at remote 0x7ffff7eaba28>)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:4194
#6  call_function (oparg=<optimized out>, pp_stack=0x7fffffffdc60)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:4119
#7  PyEval_EvalFrameEx (
    f=f@entry=Frame 0x81cb30, for file /usr/lib64/python2.7/site-packages/sane.py, line 247, in scan (self=<SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7ffff7ea6a28>, 'tl_y': <Option(index=12, name='tl-y', title='Top-left y', py_name='tl_y', cap=5, con...(truncated), throwflag=throwflag@entry=0)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:2740
#8  0x00007ffff7af7a40 in fast_function (nk=<optimized out>, na=1, n=1, 
    pp_stack=0x7fffffffddc0, func=<function at remote 0x7ffff7eabaa0>)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:4184
#9  call_function (oparg=<optimized out>, pp_stack=0x7fffffffddc0)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:4119
#10 PyEval_EvalFrameEx (
    f=f@entry=Frame 0x81c980, for file <stdin>, line 1, in <module> (), 
    throwflag=throwflag@entry=0)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:2740
---Type <return> to continue, or q <return> to quit---
#11 0x00007ffff7af929d in PyEval_EvalCodeEx (co=co@entry=0x7ffff7f25e30, 
    globals=globals@entry={'d': [('hpaio:/usb/Officejet_6700?serial=CN38BCRGHV05RQ', 'Hewlett-Packard', 'Officejet_6700', 'all-in-one')], '__builtins__': <module at remote 0x7ffff7fa2b08>, '__package__': None, 's': <SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7fff...(truncated), 
    locals=locals@entry={'d': [('hpaio:/usb/Officejet_6700?serial=CN38BCRGHV05RQ', 'Hewlett-Packard', 'Officejet_6700', 'all-in-one')], '__builtins__': <module at remote 0x7ffff7fa2b08>, '__package__': None, 's': <SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7fff...(truncated), args=args@entry=0x0, argcount=argcount@entry=0, 
    kws=kws@entry=0x0, kwcount=kwcount@entry=0, defs=defs@entry=0x0, 
    defcount=defcount@entry=0, closure=closure@entry=0x0)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:3330
#12 0x00007ffff7af93a2 in PyEval_EvalCode (co=co@entry=0x7ffff7f25e30, 
    globals=globals@entry={'d': [('hpaio:/usb/Officejet_6700?serial=CN38BCRGHV05RQ', 'Hewlett-Packard', 'Officejet_6700', 'all-in-one')], '__builtins__': <module at remote 0x7ffff7fa2b08>, '__package__': None, 's': <SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7fff...(truncated), 
    locals=locals@entry={'d': [('hpaio:/usb/Officejet_6700?serial=CN38BCRGHV05RQ', 'Hewlett-Packard', 'Officejet_6700', 'all-in-one')], '__builtins__': <module at remote 0x7ffff7fa2b08>, '__package__': None, 's': <SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, ---Type <return> to continue, or q <return> to quit---
size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7fff...(truncated)) at /usr/src/debug/Python-2.7.5/Python/ceval.c:689
#13 0x00007ffff7b127ef in run_mod (mod=mod@entry=0x6f68a0, 
    filename=filename@entry=0x7ffff7b59abf "<stdin>", 
    globals={'d': [('hpaio:/usb/Officejet_6700?serial=CN38BCRGHV05RQ', 'Hewlett-Packard', 'Officejet_6700', 'all-in-one')], '__builtins__': <module at remote 0x7ffff7fa2b08>, '__package__': None, 's': <SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7fff...(truncated), 
    locals={'d': [('hpaio:/usb/Officejet_6700?serial=CN38BCRGHV05RQ', 'Hewlett-Packard', 'Officejet_6700', 'all-in-one')], '__builtins__': <module at remote 0x7ffff7fa2b08>, '__package__': None, 's': <SaneDev(opt={'compression': <Option(index=8, name='compression', title='Compression', py_name='compression', cap=69, constraint=['JPEG'], scanDev=<...>, size=32, type=3, unit=0, desc='Selects the scanner compression method for faster scans, possibly at the expense of image quality.') at remote 0x7ffff7ea6a70>, 'tl_x': <Option(index=11, name='tl-x', title='Top-left x', py_name='tl_x', cap=5, constraint=(<float at remote 0x622eb8>, <float at remote 0x622ea0>, <float at remote 0x622e88>), scanDev=<...>, size=4, type=2, unit=3, desc='Top-left x position of scan area.') at remote 0x7ffff7ea6b48>, 'brightness': <Option(index=6, name='brightness', title='Brightness', py_name='brightness', cap=69, constraint=(0, 2000, 0), scanDev=<...>, size=4, type=1, unit=0, desc='Controls the brightness of the acquired image.') at remote 0x7fff...(truncated), flags=flags@entry=0x7fffffffe020, arena=arena@entry=0x6447a0)
    at /usr/src/debug/Python-2.7.5/Python/pythonrun.c:1373
#14 0x00007ffff7b148a0 in PyRun_InteractiveOneFlags (
    fp=fp@entry=0x7ffff70e6640 <_IO_2_1_stdin_>, 
    filename=filename@entry=0x7ffff7b59abf "<stdin>", 
    flags=flags@entry=0x7fffffffe020)
    at /usr/src/debug/Python-2.7.5/Python/pythonrun.c:860
#15 0x00007ffff7b14a8e in PyRun_InteractiveLoopFlags (
    fp=fp@entry=0x7ffff70e6640 <_IO_2_1_stdin_>, 
    filename=filename@entry=0x7ffff7b59abf "<stdin>", 
    flags=flags@entry=0x7fffffffe020)
    at /usr/src/debug/Python-2.7.5/Python/pythonrun.c:780
#16 0x00007ffff7b1512e in PyRun_AnyFileExFlags (
    fp=fp@entry=0x7ffff70e6640 <_IO_2_1_stdin_>, 
    filename=filename@entry=0x7ffff7b59abf "<stdin>", closeit=closeit@entry=0, 
    flags=flags@entry=0x7fffffffe020)
    at /usr/src/debug/Python-2.7.5/Python/pythonrun.c:749
#17 0x00007ffff7b25c4f in Py_Main (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/Python-2.7.5/Modules/main.c:640
#18 0x00007ffff6d4ed65 in __libc_start_main (main=0x4006f0 <main>, argc=1, 
    argv=0x7fffffffe1e8, init=<optimized out>, fini=<optimized out>, 
    rtld_fini=<optimized out>, stack_end=0x7fffffffe1d8) at libc-start.c:285
---Type <return> to continue, or q <return> to quit---
#19 0x0000000000400721 in _start ()
Member

manisandro commented Jan 22, 2014

Great, thanks! So the part which is failing is

/* enforce SANE_STATUS_EOF. Can be necessary for ADF scans for some backends */
do {
   st = sane_read(self->h, buffer, READSIZE, &len);
 }
while (st == SANE_STATUS_GOOD);
if (st != SANE_STATUS_EOF)
  {
    sane_cancel(self->h);
    Py_BLOCK_THREADS
    return PySane_Error(st);
  }

What's nice is that it is not actually the image transfer which is failing. I'll look at improving this code section.

Member

manisandro commented Jan 22, 2014

Could you please try setting a breakpoint at _sane.c:941 and see whether you hit that breakpoint? Thanks.

Yes, I hit 941:

image = s.scan()
[New Thread 0x7fffdffe6700 (LWP 2178)]
[Thread 0x7fffdffe6700 (LWP 2178) exited]
[New Thread 0x7fffdffe6700 (LWP 2179)]
[Thread 0x7fffdffe6700 (LWP 2179) exited]
[New Thread 0x7fffdf7e5700 (LWP 2180)]
[Thread 0x7fffdf7e5700 (LWP 2180) exited]
[New Thread 0x7fffdffe6700 (LWP 2181)]
[Thread 0x7fffdffe6700 (LWP 2181) exited]
[New Thread 0x7fffdffe6700 (LWP 2182)]
[Thread 0x7fffdffe6700 (LWP 2182) exited]
[New Thread 0x7fffdffe6700 (LWP 2183)]
[Thread 0x7fffdffe6700 (LWP 2183) exited]
[New Thread 0x7fffdffe6700 (LWP 2184)]
[Thread 0x7fffdffe6700 (LWP 2184) exited]
[New Thread 0x7fffdffe6700 (LWP 2185)]
[Thread 0x7fffdffe6700 (LWP 2185) exited]
[New Thread 0x7fffdffe6700 (LWP 2186)]
[Thread 0x7fffdffe6700 (LWP 2186) exited]
[New Thread 0x7fffdffe6700 (LWP 2187)]
[Thread 0x7fffdffe6700 (LWP 2187) exited]
[New Thread 0x7fffdffe6700 (LWP 2188)]
[Thread 0x7fffdffe6700 (LWP 2188) exited]
[New Thread 0x7fffdffe6700 (LWP 2189)]
[Thread 0x7fffdffe6700 (LWP 2189) exited]
[New Thread 0x7fffdffe6700 (LWP 2190)]
[Thread 0x7fffdffe6700 (LWP 2190) exited]
[New Thread 0x7fffdffe6700 (LWP 2191)]
[Thread 0x7fffdffe6700 (LWP 2191) exited]

Breakpoint 1, SaneDev_snap (self=0x7ffff7f62138, args=<optimized out>)
    at _sane.c:941
941        st = sane_read(self->h, buffer, READSIZE, &len);
Missing separate debuginfos, use: debuginfo-install avahi-libs-0.6.31-21.fc20.x86_64 cups-libs-1.7.0-4.fc20.x86_64 dbus-libs-1.6.12-1.fc20.x86_64 hplip-libs-3.13.11-1.fc20.x86_64 jbigkit-libs-2.0-9.fc20.x86_64 keyutils-libs-1.5.8-1.fc20.x86_64 krb5-libs-1.11.3-33.fc20.x86_64 libcom_err-1.42.8-3.fc20.x86_64 libexif-0.6.21-6.fc20.x86_64 libgcc-4.8.2-1.fc20.x86_64 libgphoto2-2.5.2-5.fc20.x86_64 libieee1284-0.2.11-15.fc20.x86_64 libjpeg-turbo-1.3.0-1.fc20.x86_64 libsane-hpaio-3.13.11-1.fc20.x86_64 libselinux-2.1.13-19.fc20.x86_64 libtiff-4.0.3-12.fc20.x86_64 libtool-ltdl-2.4.2-21.fc20.x86_64 libusbx-1.0.16-3.fc20.x86_64 libv4l-1.0.0-1.fc20.x86_64 ncurses-libs-5.9-12.20130511.fc20.x86_64 net-snmp-libs-5.7.2-15.fc20.x86_64 nss-softokn-freebl-3.15.2-2.fc20.x86_64 openssl-libs-1.0.1e-30.fc20.x86_64 pcre-8.33-2.fc20.1.x86_64 readline-6.2-8.fc20.x86_64 systemd-libs-208-9.fc20.x86_64 zlib-1.2.8-3.fc20.x86_64
943   while (st == SANE_STATUS_GOOD);
(gdb) n
944   if (st != SANE_STATUS_EOF)
(gdb) n
946       sane_cancel(self->h);
(gdb) n
[New Thread 0x7fffdffe6700 (LWP 2197)]
[Thread 0x7fffdffe6700 (LWP 2197) exited]
[New Thread 0x7fffdf7e5700 (LWP 2198)]
[Thread 0x7fffdf7e5700 (LWP 2198) exited]
947       Py_BLOCK_THREADS
(gdb) n
948       return PySane_Error(st);
(gdb) n
956 }
(gdb) n
call_function (oparg=<optimized out>, pp_stack=0x7fffffffda60)
    at /usr/src/debug/Python-2.7.5/Python/ceval.c:4100
4100                Py_XDECREF(callargs);
(gdb) n
4130        while ((*pp_stack) > pfunc) {

Member

manisandro commented Jan 23, 2014

A tentative patch is here [1]. Patched Fedora builds are here: i686 [2], x86_64 [3]. Could you please try out the patched version and report whether things work? To update pillow on your Fedora Live-CD:

  • Download python-pillow-2.3.0-4.1.fc20.$arch.rpm and python-pillow-sane-2.3.0-4.1.fc20.$arch.rpm from [2] resp [3] to a folder (i.e. $HOME/Downloads)
  • In a terminal, cd to that folder, then do sudo yum update python-pillow* (note the *)

Thanks.

[1] http://smani.fedorapeople.org/python-pillow_sane.patch
[2] http://koji.fedoraproject.org/koji/taskinfo?taskID=6443344
[3] http://koji.fedoraproject.org/koji/taskinfo?taskID=6443343

Fedora wouldn't update, asked me to use 'yum install' instead. I tried this and it appeared to install correctly, but when I run python it gives an error:

import sane
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/sane.py", line 11, in <module>
    from PIL import Image
  File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 53, in <module>
    from PIL import _imaging as core
ImportError: /usr/lib/python2.7/site-packages/PIL/_imaging.so: wrong ELF class: ELFCLASS32
Member

manisandro commented Jan 25, 2014

You downloaded the i686 version instead of the x86_64 one. Please use the rpms from http://koji.fedoraproject.org/koji/taskinfo?taskID=6443343 .

Oops. Dumb mistake, sorry. Tried it with _64 and seems to be working fine. No error messages, and I can see the scanned file as .pdf. This is great!! How do I update my Arch system?

Member

manisandro commented Jan 25, 2014

Great! Pull request submitted, see issue #503 .

On Arch, you will either need to recompile Pillow yourself with the patch, or contact the person who maintains pillow in Arch and ask him to build an updated package with the patch.

barronmo commented Feb 4, 2014

Manisandro:

The Arch package has been updated as of 2/2/14 to version 2.3.0-3, so I installed the update, however, I get the same error. Is there a way to tell if your patch is incorporated into the update?

Member

manisandro commented Feb 4, 2014

2.3.0-3 is simply a rebuild, see [1], my patch is not included (it should be in 2.4.0 if it gets merged by then). If you want to have the patch included before 2.4.0 is released, you'll need to contact the archlinux pillow maintainer (which according to [2] is Kyle Keen keenerd@gmail.com), or probably preferrably submit a bug/feature request at https://bugs.archlinux.org/.

[1] https://projects.archlinux.org/svntogit/community.git/log/trunk?h=packages/python-pillow
[2] https://projects.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/python-pillow

Looks like I will have to apply the patch myself. I noticed the file [1] listed above is no longer there. Is there another place to find it?
[1] http://smani.fedorapeople.org/python-pillow_sane.patch

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment