473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

A SANE scanner backend written in Python?

I've read many times on this newsgroup over the years that you can write
"just about anything" in Python, except perhaps a full operating system
(maybe even that...?). So, with this spirit in mind, I would like to try
to write a SANE scanner backend that I need to write, in Python rather
than C. This work is being done on Linux using Python 2.4.2.

If you are not familar with SANE, and the SANE API, it basically boils
down to supplying a libsane-<name of your backend>.so shared library
that supports a basic C interface. Example sane API calls into a backend
are: sane_init(), sane_open(), sane_start(), sane_read() and
sane_cancel(). At runtime, a backend is loaded up and its C interface is
called to determine what devices are supported by the backend, to set
options, and to actually perform a scan.

Obviously, this is an example of embedding Python, albiet with a
different end result. I have not found any examples in the wild that
embed Python in a shared library (vs. a standalone executable).

My trials so far have been fruitless. To start with, I simply took an
outline of a shared library that defined all the relevant SANE APIs,
linked it with SANE and Python, and placed a PyInitialize() in the
sane_init() function. This immediately results in a segmentation fault.
I'm not sure how to proceed from here. How would a separate .py file be
accessed in this way and how would I call "back" into Python code when a
C API was called? Is there going to be a problem of maintaining "state"
in Python between invocations of the C API?

I've also explored using Elmer for this task, but have not had luck so
far. Its also not clear to me whether this tool is appropriate for this
task.

So, what I'd be interested in knowing is whether this is a foolish
venture, or if I just have the wrong approach.

Any thoughts would be appreciated.

Thanks,

-Don
Mar 28 '06 #1
1 2452
Recompile Python and SANE with debugging enabled, if you haven't
already. That should allow you to trace back to the source of the error
using gdb (or your favorite gdb front-end). AFAIK there's no inherent
reason that embedding Python in a shared library wouldn't work. Did
you try compiling the outline of the shared library without the
PyInitialize call? Is it possible that the segfault had nothing to do
with python?

Mar 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Will | last post by:
I just discovered Python and looked briefly at one of the tutorials for beginners... It looks a lot like the old Command line Basic... I'm sure it does much more but... 1 - Can you create...
0
by: GMane Python | last post by:
Hello All! I was hoping for a bit of advise. I wanted to know if anyone has any experience with scanning. I'm mostly using Windows. I tried quickly the pyTwain, but haven't gotten too far with...
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
9
by: TPJ | last post by:
First I have to admit that my English isn't good enough. I'm still studying and sometimes I just can't express what I want to express. A few weeks ago I've written 'Python Builder' - a bash...
2
by: matt | last post by:
Hi all- I'm trying to port an ajax spell-checker (http://www.broken-notebook.com/spell_checker/index.php) to use with the moin moin wiki and have been somewhat successful. (By successful I...
13
by: Ben | last post by:
Could anyone suggest an open source project that has particularly well written Python? I am especially looking for code that people would describe as "very Python-ic". (Not trying to start any...
13
by: abhinav | last post by:
Hi guys.I have to implement a topical crawler as a part of my project.What language should i implement C or Python?Python though has fast development cycle but my concern is speed also.I want to...
31
by: David Cramer | last post by:
If you had an application that you were about to begin development on which you wanted to be cross platform (at least Mac and Windows), would you suggest using c++ and Python? I'm asking because...
25
by: Lennart Benschop | last post by:
Python has had the Decimal data type for some time now. The Decimal data type is ideal for financial calculations. Using this data type would be more intuitive to computer novices than float as its...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.