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

Discussion in 'Python' started by adsheehan@eircom.net, Jun 8, 2005.

  1. Guest

    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
    , Jun 8, 2005
    #1
    1. Advertising

  2. Greg Ewing Guest

    Re: Embedding: many interpreters OR one interpreter with many threadstates ?

    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
    Greg Ewing, Jun 9, 2005
    #2
    1. Advertising

  3. flyingfred0 Guest

    Re: Embedding: many interpreters OR one interpreter with many threadstates ?

    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:
    > 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.
    >
    flyingfred0, Jun 10, 2005
    #3
  4. Guest

    Greg Ewing wrote:
    > 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.php?func=detail&aid=1163563&group_id=5470&atid=105470
    , Jun 10, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    0
    Views:
    358
  2. bmatt
    Replies:
    2
    Views:
    308
    Frithiof Andreas Jensen
    Sep 29, 2004
  3. Craig Ringer
    Replies:
    1
    Views:
    399
    Mustafa Demirhan
    Nov 18, 2004
  4. ritesh
    Replies:
    2
    Views:
    184
    Stephan Titard
    Jul 12, 2006
  5. Garthy

    Embedding multiple interpreters

    Garthy, Dec 6, 2013, in forum: Python
    Replies:
    14
    Views:
    113
    Garthy
    Dec 7, 2013
Loading...

Share This Page