Problem with embedded python

Gordon McMillan gmcm at
Mon Jun 14 16:02:48 CEST 1999

Ben writes:
>     I have embedded python into a win32 c++ application using
> PyRun_SimpleFile. This executes a python script at regular (25 times
> a second-ish) intervals. Also included in this C++ application is a
> procedure which handles the window messages, which I have also tried
> to script. Unfortunately, running any script in this function
> crashes windows with a nasty protection fault. Do I need to run my
> scripts on seperate threads... or in different interpreters. or is
> this genuinely a bug..

It seems likely that the procedure handling windows messages is being 
executed by a different thread than the one running PyRun_SimpleFile. 
In which case you will need to establish 2 thread states when you 
start up Python, and use one for each purpose. If the work they are 
doing is completely disjoint, you could use 2 different interpreter 
states. But Python needs to know that it is operating in a threaded 
environment, and has to build objects which shadow the OS threads. 

The hard part is getting it started; after that it should just work.
And it's not actually hard to get it started, just confusing. Check
out the pysvr demo. You should probably direct further questions to
the Thread SIG. 

- Gordon

More information about the Python-list mailing list