Accessing a lock object in a C module

David Fisher python at rose164.wuh.wustl.edu
Thu Feb 3 13:47:51 CET 2000


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

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


> David Fisher <python at rose164.wuh.wustl.edu> 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>.

What-i-know-about-language-design-could-fit-in-a-box-of-matches-witho
ut-removing-the-matches-ly yr's - david








More information about the Python-list mailing list