Embedding Python in a multi-threaded C++ application

Discussion in 'Python' started by Mustafa Demirhan, Nov 9, 2004.

  1. Hello,

    I am trying to add Python scripting support to one of my applications
    and I really need some help regarding the thread terminations.

    The application is a multi-threaded Windows application and multiple
    threads need to run Python code from time to time. Everything works
    fine when all the threads operate without any errors. Each thread
    creates a thread state, acquires the global lock, call the Python
    files and then release the lock when they are done. However,
    sometimes, some of these threads needs to be terminated from the main
    in the middle of their operation (this generally is done by the user -
    if the Python code is not working as expected, or doing something very
    very long, the user is able to terminate the thread from the main
    GUI). The problem here is that if the user terminates the thread, the
    thread never releases the lock.

    So, my question is: is there a way to safely terminate a running
    thread? If not, is there a way to release the lock of a thread from
    another thread (from the main thread)?
    If none of these can be done, what happens if I call Py_Finalize and
    finalize the Python Interpreter and the re-start it by Py_Initialize
    and PyEval_InitThreads. Will that free all the resources allocated by
    the previous interpreter?

    I desperately need help. I couldnt find a good documentation on the
    Internet. Any helps would be greatly appreciated.

    Best wishes,
    Mustafa Demirhan
     
    Mustafa Demirhan, Nov 9, 2004
    #1
    1. Advertisements

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. Jesper Nilsson

    Embedding Python in a threaded app

    Jesper Nilsson, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    348
    Jesper Nilsson
    Nov 3, 2003
  2. Mustafa Demirhan
    Replies:
    0
    Views:
    362
    Mustafa Demirhan
    Nov 9, 2004
  3. cakmak
    Replies:
    1
    Views:
    662
    Andrew Thompson
    Jan 10, 2007
  4. ian douglas
    Replies:
    2
    Views:
    1,163
    Randy Howard
    Jul 30, 2004
  5. Replies:
    0
    Views:
    489
  6. Joe Holloway
    Replies:
    0
    Views:
    305
    Joe Holloway
    Jun 16, 2009
  7. Caleb Tennis
    Replies:
    3
    Views:
    225
    Tanaka Akira
    Feb 8, 2005
  8. shooshx
    Replies:
    2
    Views:
    489
Loading...