Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Embedding Python in a multi-threaded C++ application

Thread Tools

Embedding Python in a multi-threaded C++ application

Mustafa Demirhan
Posts: n/a

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
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedding a python console inside a python application Zorigaman Python 1 08-17-2009 10:26 PM
Embedding Python: Creating Python Class from Application Kakacek Python 1 01-12-2006 04:32 PM
Question: Threading and embedding python in an application David Harrison Python 3 05-10-2005 08:44 PM
Re: Embedding Python in a multi-threaded C++ application Mustafa Demirhan Python 0 11-09-2004 10:08 PM
Embedding Python in a multi-threaded C++ application Mustafa Demirhan Python 0 11-09-2004 07:06 PM