473,385 Members | 1,925 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,385 software developers and data experts.

questions on dynamically binding the Python interpreter

has
Hi all, need a little bit of advice on dynamically binding an embedded
Python interpreter.

First, the code for anyone that wants a look:

http://trac.macosforge.org/projects/...nt/trunk/PyOSA

It's a Python OSA component for OS X. The idea is that you wrap up a
scripting language interpreter as a Carbon Component Manager component
(similar to writing a COM component); applications can then call the
OSA API to load this component into memory whenever they need to run
scripts written in that language. The advantage of this approach over
embedding an interpreter directly in the application is that it's
language-agnostic, so application users can write their scripts in any
language they like (AppleScript, JavaScript, Python, etc.), as long as
there's an OSA component available for it (AppleScript, JavaScriptOSA,
PyOSA, etc.). Great concept - at least in theory.

Now, one of the things about the OSA is that, as one of the old MacOS
school, it was pretty much designed on the assumption that
interpreters would be hosted by the application process itself.
Whereas Python is more of the Unix school, and its own preference
would no doubt be to run as separate processes from the main
application process, with two-way IPC to hook the two together. I'll
likely attempt the latter approach later on (which'll no doubt open a
whole new can of worms), but for now I'm having a go at the former as
it's appears a bit simpler to implement (at least on paper) and will
have better runtime performance (since there's no IPC overhead).

For flexibility, and compatibility with application processes that may
already a Python framework loaded, I'm linking Python dynamically via
CoreFoundation's CFBundle API (which basically provides a nice wrapper
around dlopen &co., amongst other things). I've made some reasonable
progress so far, and the pythonloader code can now locate and bind a
Python.framework without triggering bus errors or anything (a big
achievement for me;). However, there's a couple of places I'm a bit
uncertain on how to proceed:

1. Py_IncRef() and Py_DecRef() only appear to have been added in
Python 2.4; is this right? I really need to support Python 2.3 as well
(since that's the version included as standard on OS X 10.3 & 10.4).
At the moment when 2.3 is imported I'm providing it stubs of these
functions that don't really do anything except leak like sieves;
obviously I'd like to replace these. Do I need to start copying and
pasting chunks of header/code out of Python 2.3, or is there a better
way of doing things?

2. I need to make several C functions callable from within the Python
code. Actually these are part of a larger ADT - the opaque data being
passed in separately as a CObject - but implementing them as a Python
type was going to be more work so the ADT approach seemed like a good
idea at the time. At the moment I'm using PyMethodDef +
Py_InitModule4() to wrap those C functions as an extension and inject
it into the interpreter's module namespace; the problem I've found is
that this API is version-sensitive (e.g. 1012 in older Python vs 1013
in newer). Is there some other way to expose those C function to
Python that isn't version-sensitive? If not, what's the best way to
work with the existing API so that users don't get inflicted with
warnings or worse?
Lastly, one other question not directly related to the above: I would
like to provide a degree of insulation between unrelated scripts
(separate module namespaces in particular); and while I realise they
still provide than perfect separation, sub-interpreters do seem to be
the one and only game in town as far as in-process solutions go. Just
how badly am I going to smoke things when I try to enable the sub-
interpreter support? Should I take out house insurance, move well
clear of inhabited areas, etc? Anywhere I can get more information on
the techniques and pitfalls involved? (The Python documentation is
terribly thin on this stuff.)

Many thanks, and apologies for length,

has

Mar 1 '07 #1
0 1522

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

Similar topics

0
by: jordi | last post by:
Hi, I'm starting to use Python embedded in a C program. I'm using Python to execute several scripts using as a variables information retrieved for several multithread "agents" written in C. ...
7
by: Elaine Jackson | last post by:
Two quick newbie questions: 1) Does Python have passing-by-reference? 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the Python "copy" module (if I understand...
2
by: bearophile | last post by:
Hello, I have few more things to say/ask (left from a discussion in another Python Newsgroup). Is it possibile (and useful) to write few small sub-sections of the Python interpreter in Assembly...
3
by: digitalsubjunctive | last post by:
Hey, I just started on Python and have a few questions I couldn't find answers to on the Python site or it's tutorial. 1. I notice a few "compiled python" files (indicated by reddish snake...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
1
by: Petr Prikryl | last post by:
Do you think that the following could became PEP (pre PEP). Please, read it, comment it, reformulate it,... Abstract Introduction of the mechanism for language extensions via modules...
14
by: shamirza | last post by:
Question Do ActiveX DLLs made in VB still need the VB runtimes on the machine? ________________________________________ Answer In a word, Yes. Visual Basic does not support what is known...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
9
by: jezonthenet | last post by:
I started using Python a couple of days ago - here are a few questions: * Doesn't the __main__() method automatically execute when I run my python program? * Only when I do an import of my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.