Threading + embedding = System Dump.
Gordon McMillan
gmcm at hypernet.com
Tue Jun 27 15:47:05 EDT 2000
Arinté wrote:
[Gordon]
>> That sounds very much like there is no multithreading.
>>
>> So why doesn't "diz[0].write(mx)" block? Or does it?
>It doesn't need too. The data is queued in a seperate subsystem. My
>app only cares if the subsystem couldn't receive the data, so the
>response is quick no need to block. This specific \x1b\x47 command
>tells when the device actually finished, I don't always want to wait for
>that .
OK, so Python calls C++ (through "diz[0].write(mx)") which does it, then
returns to Python. The Python script then goes on and finishes.
>> Is the real problem here that you're using one of the PyRun_ calls
>> when
>you
>> need to go down a level and use PyImport_ etc. so the C++ has some
>> control over what's going on?
>Seemed like I can only run a script once. If I tried to run the same
>script two times in a row the second time it did nothing, all the import
>calls return successfully both times. I don't Py_Finalize until the dll
>is unloaded.
Well, you didn't answer the question, but you provided enough clues. You
need to use a module, not a script. You need to move your top-level logic
into functions. You need to PyImport the module, then fish the functions
out of the module dict and call them. One function does the
"diz[0].write(mx)" and then returns. Later, when the C++ has caught the
relevant event, it can call the other Python function.
http://www.mcmillan-inc.com/embed2.html demonstrates most of this.
>Why, is it that if use python Event.wait function, the app crashes, as
>oppossed to popping up a messagebox and manually closing that box when I
>see the message come thru? Does wait shut down the thread the script is
>running on in some sense? I would try to do a notify from c++ on the
>python Event, but it seems I can't get any access to python when it is
>in the wait state?
You have only one (Python) thread going. With only one thread, Python
optimizes away the tstate, hence your crash. Multithreading Python in an
embedded app with callbacks is a nightmare - you will have to have valid
tstates for all C++ threads that call into (or callback into) Python.
Review the 100s of messages on the threads SIG concerning making this part
of the API sane before attempting it.
- Gordon
More information about the Python-list
mailing list