Embedding and threads

Mark Hammond mhammond at skippinet.com.au
Thu Nov 4 11:00:10 CET 1999


This is a huge source of confusion, and I cant remember the rules any
more.

For working code, see the "CEnterLeavePython" class defined in the
pywintypes module (I can send you the source if you dont have them
handy).

For a long and protracted discussion about this and much more, see the
thread-sig archives from around 12 months ago - this was discussed in
so much detail it made my nose bleed :-)

Mark.

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Thomas Heller
> Sent: Thursday, 4 November 1999 6:51
> To: python-list
> Subject: Embedding and threads
>
>
> While embedding python in a DLL I'm writing (we are talking
> Windows here),
> I encountered the following confusion:
>
> Threads are created in the application from C. From reading the docs
I
> understood that I must 'boot the thread' into existance by
> creating a thread
> state data structure (with PyThreadState_New(), passing the
> PyInterpreterState *interp pointer which I saved from the
> main thread),
> then acquire the interpreter lock, and finally store the thread
state
> pointer before using the Python/C API from this thread.
>
> I do this in the DllMain() function in the DLL_THREAD_ATTACH branch.
>
> This all works very well, but what happens if I also create threads
> from python? These threads will be initialized by python, so
> I assume the thread state data structure is already created.
>
> How do I ask python if the thread state already exists for a
> given thread?
>
> Thomas Heller
> ION-TOF GmbH
>
>
> --
> http://www.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list