Semaphore question

MDK mdk at mdk.com
Thu Jan 31 10:06:49 EST 2002


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