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

Embedding: many interpreters OR one interpreter with many thread states ?


Hi,

Does anyone know the reasoning or pros/cons for either (in a
multi-threaded C++ app):

- creating many sub-interpreters (Py_NewInterpreter) with a thread
state each

Or

- creating one interpreter with many thread states (PyThreadState_New)
When do I choose one approach over the other and why ?

Thanks

Alan

Jul 19 '05 #1
3 1810
ad*******@eircom.net wrote:
- creating many sub-interpreters (Py_NewInterpreter) with a thread
state each

Or

- creating one interpreter with many thread states (PyThreadState_New)


My understanding is that using multiple interpeters isn't
really supported properly, despite there being apparent
support in the API. So I suggest using a single interpeter
with multiple threads.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
Jul 19 '05 #2
Of course, with multiple threads in one process, it's important to know
about the dreaded global interpreter lock (GIL) --
http://docs.python.org/api/threads.html

With one instance of the interpreter, only one Python thread will be
running at a time, no matter how many CPUs you have in the system.
Greg Ewing wrote:
ad*******@eircom.net wrote:
- creating many sub-interpreters (Py_NewInterpreter) with a thread
state each

Or

- creating one interpreter with many thread states (PyThreadState_New)

My understanding is that using multiple interpeters isn't
really supported properly, despite there being apparent
support in the API. So I suggest using a single interpeter
with multiple threads.

Jul 19 '05 #3

Greg Ewing wrote:
ad*******@eircom.net wrote:
- creating many sub-interpreters (Py_NewInterpreter) with a thread
state each

Or

- creating one interpreter with many thread states (PyThreadState_New)


My understanding is that using multiple interpeters isn't
really supported properly, despite there being apparent
support in the API. So I suggest using a single interpeter
with multiple threads.


Huh. Mod_python uses multiple interpreters and within each
interpreter could be running multiple threads at one time
corresponding to different incoming HTTP requests.

It hasn't helped though that a bug was introduced in Python
2.3.5/4.0 which has been causing grief for some users creating
additional threads from within Python code itself. :-(
http://sourceforge.net/tracker/index...70&atid=105470

Jul 19 '05 #4

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

Similar topics

7
by: Wenning Qiu | last post by:
I am researching issues related to emdedding Python in C++ for a project. My project will be running on an SMP box and requires scalability. However, my test shows that Python threading has very...
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. ...
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 application running on Solaris. Python will enable end users to customize and re-program many aspects of the application. I expect that the C++...
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...
3
by: dmoore | last post by:
Hi Folks: I have a question about the use of static members in Python/C extensions. Take the simple example from the "Extending and Embedding the Python Interpreter" docs: A simple module...
7
by: skip | last post by:
This question was posed to me today. Given a C/C++ program we can clearly embed a Python interpreter in it. Is it possible to fire up multiple interpreters in multiple threads? For example: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.