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

Embedding Python question.

Dear all,

I've successfully embedded the Python interpreter into a set of C/C++
application programs that use a larger library project with information
from http://docs.python.org/api/api.html and
http://docs.python.org/ext/ext.html. Now I want to wrap classes and
functions from the associated libraries so that I can write new
applications completely in Python, but I'm not entirely sure how to
start because I have some problems understanding which is the best way.
It would be nice if someone could answer the following questions and
clarify this matter:

- until now I've used the approach as documented in
http://docs.python.org/ext/extending...embedding.html to extend the
embedded interpreter and that works pretty well. I'd like to use a
similar approach for other C applications. Can I write a C library that
implements this technique and link it into all C applications that need
Python support, or is there a better, more elegant way?

- in the documentation, there's an example that illustrates the creation
of a python module for pure extending of a python script (the Noddy
stuff). Do I have to make a separate module for each library I want to
wrap? If yes, how can I manage the case where two libraries can access
each other?

- if I write an extension module, how can I handle the case where the C
wrapper methods want to call back into the same Python interpreter instance?

- I think my questions break down into a reference to documentation
where a similar problem is explained in detail. Does anyone have such
information?

Thanks!
Thomas.
Jun 27 '08 #1
1 1324
En Tue, 20 May 2008 06:35:23 -0300, Thomas Troeger
<th****************@siemens.comescribió:
I've successfully embedded the Python interpreter into a set of C/C++
application programs that use a larger library project with information
from http://docs.python.org/api/api.html and
http://docs.python.org/ext/ext.html. Now I want to wrap classes and
functions from the associated libraries so that I can write new
applications completely in Python, but I'm not entirely sure how to
start because I have some problems understanding which is the best way.
It would be nice if someone could answer the following questions and
clarify this matter:

- until now I've used the approach as documented in
http://docs.python.org/ext/extending...embedding.html to extend the
embedded interpreter and that works pretty well. I'd like to use a
similar approach for other C applications. Can I write a C library that
implements this technique and link it into all C applications that need
Python support, or is there a better, more elegant way?
(I don't get what you mean by "this technique" and how would you write a
library)
- in the documentation, there's an example that illustrates the creation
of a python module for pure extending of a python script (the Noddy
stuff). Do I have to make a separate module for each library I want to
wrap? If yes, how can I manage the case where two libraries can access
each other?
Normally, yes, you'd write a wrapping module for each library. If both
access each other - well, you'd manage it the same way as you would do it
in C; you're just providing an interfase for calling the functions from
Python. (Hmm, maybe I have an "imagination crisis" today?)
- if I write an extension module, how can I handle the case where the C
wrapper methods want to call back into the same Python interpreter
instance?
I think there is no problem - unless your program is multithreaded, then
you should not release the GIL when calling into your extension if there
is a chance the C code may call Python code.
--
Gabriel Genellina

Jun 27 '08 #2

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

Similar topics

4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
1
by: Martin | last post by:
Greetings, I am new to python and wish to embed python in an 3D graphics application to provide application automation. The high level goal is to be able to drive my app from a script for batch...
2
by: Roose | last post by:
With some googling I have found these resources: http://docs.python.org/ext/win-dlls.html http://www.python.org/doc/faq/windows.html I have a large Win32/MFC/C/C++ application that has an...
1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
0
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
0
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
4
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application running on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.