Multiple Interpreters In a Single Thread

Discussion in 'Python' started by bmatt, Sep 23, 2004.

  1. bmatt

    bmatt Guest

    I am trying to support multiple interpreter instances within a single
    main application thread. The reason I would like separate interpreters
    is because objects in my system can be extended with python scripts
    via a well defined interface (i.e. The onCreate script will be called
    when the object is created).

    So...Is it necessary to use multiple interpreters since each script I
    import will be given its own module name and therefore the predefined
    functions can be resolved using that module name?

    If it is necessary then how is this accomplished? I have tried using
    Py_NewInterpreter() but have been getting a strange crash (invalid
    thread state).

    Another concern I have is that I would like to be able to support
    scripts defining their own application loop like functions. These
    functions will need to be able to pause and wait for the next
    application loop iteration before continuing. So...is there a way to
    stop the interpreter ( via a call to an application defined function
    like system.waitIteration() ), save the state of the interpreter and
    continue processing when the application says it is ready?

    I know these are kind of high level and vague questions but I am just
    in the proof of concept and design phase and need to make sure some of
    my ideas are feasible. Any information would be appreciated.

    Thanks
    bmatt, Sep 23, 2004
    #1
    1. Advertising

  2. bmatt

    bmatt Guest

    I wanted to follow up on my post and let everyone how I decided to
    tackle this problem. If you see any inherent problems with my solution
    or know of a better way to handle it then let me know.

    I decided to run each script in a separate thread but force them to
    run synchronously. This may seem like overkill but it allows me to use
    separate python interpreters (secondary concern) and facilitates the
    scripts ability to relinquish control back to the main application
    thread so that it can wait a single program loop iteration or wait a
    specific amount of time before continuing or wait for some other
    defined event.



    (bmatt) wrote in message news:<>...
    > I am trying to support multiple interpreter instances within a single
    > main application thread. The reason I would like separate interpreters
    > is because objects in my system can be extended with python scripts
    > via a well defined interface (i.e. The onCreate script will be called
    > when the object is created).
    >
    > So...Is it necessary to use multiple interpreters since each script I
    > import will be given its own module name and therefore the predefined
    > functions can be resolved using that module name?
    >
    > If it is necessary then how is this accomplished? I have tried using
    > Py_NewInterpreter() but have been getting a strange crash (invalid
    > thread state).
    >
    > Another concern I have is that I would like to be able to support
    > scripts defining their own application loop like functions. These
    > functions will need to be able to pause and wait for the next
    > application loop iteration before continuing. So...is there a way to
    > stop the interpreter ( via a call to an application defined function
    > like system.waitIteration() ), save the state of the interpreter and
    > continue processing when the application says it is ready?
    >
    > I know these are kind of high level and vague questions but I am just
    > in the proof of concept and design phase and need to make sure some of
    > my ideas are feasible. Any information would be appreciated.
    >
    > Thanks
    bmatt, Sep 27, 2004
    #2
    1. Advertising

  3. "bmatt" <> wrote in message
    news:...
    > I am trying to support multiple interpreter instances within a single
    > main application thread.


    I think it sounds tricky and doomed to endless debugging - given that one
    does not really have full control over the interpreter, not many people "go
    there" and therefore there may lurk undocumented implementation & machine
    detail that change suddently ...

    > Any information would be appreciated.


    I *guess* that what you want to do is to be able to attach/detach
    functionality to an application so that 'the user' can build/customise his
    own custom tool from a set of available building-blocks and some runtime
    configuration tool?

    If you base your framework on Pyro and design a protocol for registration,
    location and inter-connection of Services, I think your life might be
    simpler; With Pyro your independent Python Thread will be in separate
    applications, but the Pyro interface makes all objects appear local to the
    application using them. I like it.

    http://pyro.sourceforge.net/
    Frithiof Andreas Jensen, Sep 29, 2004
    #3
    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. Maciej Sobczak

    Multiple interpreters in a single process

    Maciej Sobczak, Jan 5, 2004, in forum: Python
    Replies:
    1
    Views:
    386
  2. Paul Miller
    Replies:
    4
    Views:
    318
    Paul Miller
    Jan 23, 2004
  3. Replies:
    3
    Views:
    314
  4. Replies:
    0
    Views:
    258
  5. grbgooglefan
    Replies:
    24
    Views:
    1,771
    Graham Dumpleton
    Sep 8, 2009
Loading...

Share This Page