openpaperwork / pyinsane

Python library to access and use image scanners (Linux/Windows/etc) (Sane/WIA) -- Moved to Gnome's Gitlab
https://gitlab.gnome.org/World/OpenPaperwork/pyinsane
63 stars 24 forks source link

Examples/ scan.py #31

Closed astadtla closed 7 years ago

astadtla commented 7 years ago

======== RESTART: /home/pi/Downloads/pyinsane-stable/examples/scan.py ======== Output file: /home/pi/Documents/LinearBookScanner/test.jpg Looking for scanners ... Devices detected:

Will use: 'genesys:libusb:001:005' (Canon, LiDE 120, flatbed scanner)

Unable to set scanner option [source]: Option is not active

Scanning ...
|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\ Writing output file ... Traceback (most recent call last): File "/home/pi/Downloads/pyinsane-stable/examples/scan.py", line 113, in main() File "/home/pi/Downloads/pyinsane-stable/examples/scan.py", line 105, in main img = scan_session.images[0] File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 202, in __get_imgs imgs = remote_do('get_images', self._scanner) File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 68, in remote_do length = struct.unpack("i", length)[0] struct.error: unpack requires a bytes object of length 4

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pi/Downloads/pyinsane-stable/examples/scan.py", line 115, in pyinsane2.exit() File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 120, in exit remote_do('exit') File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 56, in remote_do os.write(fifo_c2s, length) BrokenPipeError: [Errno 32] Broken pipe

jflesch commented 7 years ago

As indicated in the README, the sane implementation fork, and the job is actually done by a background process. Here the background process has crashed (which closed the pipe used to communicate, raising the exceptions we can see here). Unfortunately, we don't have the stacktrace for the background process visible here.

The following patch will disable the use of the background process. It should make the correct stacktrace visible. Can you try again with this patch please ?

diff --git a/pyinsane2/__init__.py b/pyinsane2/__init__.py
index bd3a6e7..b596ed2 100644
--- a/pyinsane2/__init__.py
+++ b/pyinsane2/__init__.py
@@ -25,7 +25,7 @@ elif sys.platform == "darwin":
     # The dedicated process appear to crash on MacOSX. Don't know why.
     from .sane.abstract import *
 else:
-    from .sane.abstract_proc import *
+    from .sane.abstract import *

 def __normalize_value(value):
astadtla commented 7 years ago

So I figured out the issue, I had 1 GB of Ram on the machine and it was running out of memory on the line img.save(output_file, "JPEG"). It is running on a raspberry pi 3 so I increased the available memory by another GB with a swap file and it used up about 600 MB of that but was able to save successfully. The max I could scan was 600 DPI if I have the swap file activated if not it was 150 I think.

sorry, I am primarily a .net guy so I am not really sure what to do with that patch

jflesch commented 7 years ago

Regarding the patch, the idea was basically:

cd /tmp
git clone https://github.com/jflesch/pyinsane
cd pyinsane
patch -p1 < ~/Download/pyinsane.patch
sudo python3 ./setup.py install

(or something similar)