Semaphore question

MDK mdk at mdk.com
Thu Jan 31 10:22:03 EST 2002


Never mind.  I figured out what I was doing wrong. It was in a 'try' so I
did not see the error.  I just needed to add 'self.' to the lock object.
Oops.

Thanks.


"MDK" <mdk at mdk.com> wrote in message
news:a3bmia$171cgl$1 at ID-98166.news.dfncis.de...
> When I do this I never aquire a lock.
>
> print 'we have data'
> lock.aquire()
> print 'lock aquired'
> lock.release()
>
> I get 'we have data' printed out several times but never get 'lock
aquired'.
>
> I put the same print statements around the other lock and it is properly
not
> getting called because data never gets into the list.  So another lock is
> not being aquired.
>
> I have also tried using:
> import threading
> lock=threading.Lock()
>
> This has the same results.  How can I figure out why I can't aquire a
lock?
> Like I said above, I am sure that the other lock is not being called.
>
> Thanks.
>
> "Jesper Olsen" <jolsen at mailme.dk> wrote in message
> news:cf0ad9fb.0201310349.22f5d5ae at posting.google.com...
> > If all you need to share between threads is a list,
> > the Queue module is a good choise.
> >
> > Alternatively you can explicitly set up mutexes to ensure that
> > only one thread accesses your data at a time:
> >
> > import thread
> > lock=thread.allocate_lock()
> >
> > ...
> >
> > lock.aquire()
> > #manipulate shared data here
> > lock.release()
> >
> > Cheers
> > Jesper
> >
> > "MDK" <mdk at mdk.com> wrote in message
> news:<a39q4u$16cjiu$1 at ID-98166.news.dfncis.de>...
> >
> > > Could someone give me a clear example of how to use Semaphore so that
> the
> > > threads properly acquire and release the Data list?
> > >
> > > Thank you.
>
>





More information about the Python-list mailing list