Re: embedding: forcing an interpreter to end

Discussion in 'Python' started by Miki Tebeka, Dec 21, 2004.

  1. Miki Tebeka

    Miki Tebeka Guest

    Hello dan,

    > > How about: PyRun_String("from os import _exit;
    > > _exit(0)") ?

    >
    > Clever! But, _exit() will terminate my entire
    > process, not just the offending interpreter. And I
    > can't use a separate child process on uclinux.

    You have a Python port to uClinux?

    > Any other ideas?

    1.
    Maybe: PyRun_String("raise SystemExit")?
    Which supposed to be less brute.
    2.
    Is there any signal handler you can use in your C program? Maybe signling
    yourself will get the control back to the C program and then you can kill
    the interpreter.

    Bye.
    --
    ------------------------------------------------------------------------
    Miki Tebeka <>
    http://tebeka.bizhat.com
    The only difference between children and adults is the price of the toys
     
    Miki Tebeka, Dec 21, 2004
    #1
    1. Advertising

  2. Miki Tebeka

    Guest

    > Is there any signal handler you can use in your C program? Maybe
    signling
    > yourself will get the control back to the C program and then you can

    kill
    > the interpreter.


    Well, the app is multi-threaded, so I do have a big issue getting
    control back to my C program. I just can not seem to cleanly stop the
    interpreter. The best I could do is:

    void terminateInterpreter( PyInterpreterState *interp )
    {
    PyGILState_STATE gilstate;
    PyObject *exc;
    PyThreadState *tstate;

    gilstate = PyGILState_Ensure();
    tstate = PyThreadState_Swap(interp->tstate);

    exc = PyString_FromString("Die");
    PyThreadState_SetAsyncExc(interp->tstate->thread_id, exc);
    Py_DECREF(exc);

    PyThreadState_Swap(tstate);
    PyGILState_Release(gilstate);
    }

    > You have a Python port to uClinux?


    Nope, not yet. That would have been my next post :) I thought there
    would have been much more work on cross-compiling and porting Python.
    I may need to reconsider if Python is appropriate; the other
    possibiities are javascript or lua.
     
    , Dec 22, 2004
    #2
    1. Advertising

  3. Miki Tebeka

    Miki Tebeka Guest

    Hello pdectm,

    > > You have a Python port to uClinux?

    >
    > Nope, not yet. That would have been my next post :) I thought there
    > would have been much more work on cross-compiling and porting Python.

    The problem is with Python's build proces, it 1'st created pgen and then
    use it for the next stage.
    This makes cross compilation very intersting :)

    > I may need to reconsider if Python is appropriate; the other
    > possibiities are javascript or lua.

    Lisp/Scheme?
    (See http://tinyscheme.sourceforge.net/download.html for a very small
    impelementation)

    Bye.
    --
    ------------------------------------------------------------------------
    Miki Tebeka <>
    http://tebeka.bizhat.com
    The only difference between children and adults is the price of the toys
     
    Miki Tebeka, Dec 22, 2004
    #3
  4. Miki Tebeka

    Peter Hansen Guest

    wrote:
    > Well, the app is multi-threaded, so I do have a big issue getting
    > control back to my C program. I just can not seem to cleanly stop the
    > interpreter. The best I could do is:
    >
    > void terminateInterpreter( PyInterpreterState *interp )

    [...]
    > PyThreadState_SetAsyncExc(interp->tstate->thread_id, exc);
    > Py_DECREF(exc);


    As I recall, there is a return value from SetAsyncExc()
    which according to the documentation you *must* check
    and handle appropriately if you want to avoid some
    unspecified Bad Things from happening.

    There was some recent (2-3 weeks ago?) discussion in the
    newsgroup/mailing list about this as well, if you want
    to check the archives.

    -Peter
     
    Peter Hansen, Dec 22, 2004
    #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. Earl Teigrob
    Replies:
    0
    Views:
    403
    Earl Teigrob
    Aug 11, 2003
  2. Replies:
    1
    Views:
    448
    Diez B. Roggisch
    Dec 20, 2004
  3. dan charnitsky
    Replies:
    1
    Views:
    309
    Peter Hansen
    Dec 27, 2004
  4. Miki Tebeka
    Replies:
    2
    Views:
    338
    Fuzzyman
    Feb 1, 2005
  5. Replies:
    3
    Views:
    762
    Ziga Seilnacht
    Jan 3, 2007
Loading...

Share This Page