Skip to content
This repository has been archived by the owner on Dec 30, 2018. It is now read-only.

Multi Threading scanning #32

Open
astadtla opened this issue Apr 3, 2017 · 4 comments
Open

Multi Threading scanning #32

astadtla opened this issue Apr 3, 2017 · 4 comments
Labels

Comments

@astadtla
Copy link

astadtla commented Apr 3, 2017

I have a use case where I need to scan 2 different scanners at the same time. when I attempt to multi thread pyinsane2 I get the following
TestScanMultiple.txt

error. attached is the python script that generated this error. Any help would be greatly appreciated.

===== RESTART: /home/pi/Documents/LinearBookScanner/TestScanMultiple.py =====

Device Id: 0Device Id: 1

init in thread: 1init in thread: 2

Devices Recieved in thread: 2
Exiting in thread: 2
Exception in thread Thread-1:
Traceback (most recent call last):
File "/home/pi/Documents/LinearBookScanner/TestScanMultiple.py", line 12, in Scan
devices = pyinsane2.get_devices()
File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 268, in get_devices
for x in remote_do('get_devices', local_only)
File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 69, in remote_do
result = os.read(fifo_s2c, length)
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Documents/LinearBookScanner/TestScanMultiple.py", line 16, in Scan
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)
OSError: [Errno 9] Bad file descriptor

@jflesch
Copy link
Member

jflesch commented Apr 3, 2017

Please call pyinsane2.init() only once from a single thread (for instance in your function Program()). (same goes for pyinsane2.exit()).

@astadtla
Copy link
Author

astadtla commented Apr 3, 2017

TestScanMultiple.txt
I moved all of the references to pyinsane2 outside of the threads but when i get to the section to start the scan in the any one of the threads:
try:
while True:
scan_session.scan.read()
except EOFError:
pass
i get another error:
===== RESTART: /home/pi/Documents/LinearBookScanner/TestScanMultiple.py =====
Device Id: 0Device Id: 1

Exiting in thread: 1Exiting in thread: 2

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Documents/LinearBookScanner/TestScanMultiple.py", line 18, in Scan
scan_session.scan.read()
File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 173, in read
return remote_do('scan_read', self._scanner_name)
File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 69, in remote_do
result = os.read(fifo_s2c, length)
MemoryError
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Documents/LinearBookScanner/TestScanMultiple.py", line 18, in Scan
scan_session.scan.read()
File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 173, in read
return remote_do('scan_read', self._scanner_name)
File "/usr/local/lib/python3.5/dist-packages/pyinsane2/sane/abstract_proc.py", line 70, in remote_do
assert(len(result) == length)
AssertionError

@jflesch
Copy link
Member

jflesch commented Apr 3, 2017

MemoryError

How much free memory does your device has ? It seems it's running out of memory.

Unfortunately, Pyinsane uses quite a lot of memory to store the chunk of the images. In another bug report, someone reported having issues scanning at 600dpi with only 1GB of ram (raspberry pi).

@astadtla
Copy link
Author

astadtla commented Apr 4, 2017

I am using a pi, but I have a swap file that adds a GB so 2 in total. I am only scanning at 150 dpi so it should not be to much of a hog at that level. Was the error replicated on your machine with the script I attached in the previous comment?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants