Accessing a lock object in a C module

David Fisher python at
Thu Feb 3 07:47:51 EST 2000

>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 2/3/00, 4:42:48 AM, Konrad Hinsen <hinsen at> wrote 
regarding Re: Accessing a lock object in a C module:

> David Fisher <python at> writes:

> > The struct is at the top of threadmodule.c:
> > /* Lock objects */
> >
> > typedef struct {
> >     PyObject_HEAD
> >     PyThread_type_lock lock_lock;
> > } lockobject;

> Fine, but I don't have access to this from another C module. Of course
> I could copy the structure to my own code and hope that it will never
> change in threadmodule, but that's not my preferred solution.
> --

Ah, well, i see two options then, if you are still opposed to calling 
PyObject_CallMethod.  You could incorporate threadmodule.c into your 
program, calling it mythreadmodule.c (or something), and make calls to 
your module to create lock objects.  Threadmodule.c uses the python C 
api for threads, so nobody could (should?) change the implementation 
out from under you.  Of course, if you wanted to use Lock, Rlock from 
the threading module, you'd have to modifiy those and include them in 
your project.  This sort of thing could quickly get out of hand.

Alternately, after looking at the include files python does have, and 
consulting my years (zero) of language design experience, i figure 
python needs a threadobject.h file, for exactly your kind of 
situation.  It could have the struct for lock_oject and export the 
lock methods.  I hear python 1.6 is supposed to go into alpha in a 
month or so. You could submit a patch, and have it incorporated before 
you've forgotten why you needed it <wink>.

ut-removing-the-matches-ly yr's - david

More information about the Python-list mailing list