Re: Read-write lock for Python

2011-04-29 Thread Geoff Bache
On Fri, Apr 29, 2011 at 12:38 AM, Ryan Kelly r...@rfk.id.au wrote:
 On Thu, 2011-04-28 at 07:02 -0700, Geoff Bache wrote:
 Hi all,

 I currently find myself needing a Python read-write lock. I note that
 there is none in the standard library, but googling python read-write
 lock quickly produced 6 different competing examples, including two
 languishing patch proposals for the standard library.

 I can always pick a random one and hope for the best, but I was hoping
 someone here might have a tip for one that has been used and debugged
 and is likely to work.

 I wrote and have used the SHLock class in threading2 which should do
 what you need.  Don't know about likely to work but if it doesn't, I'd
 like to hear about it so I can fix it :-)

That's good enough for me :) Thanks, I'll give it a try.

/Geoff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Jean-Michel Pichavant

Geoff Bache wrote:

Hi all,

I currently find myself needing a Python read-write lock. I note that
there is none in the standard library, but googling python read-write
lock quickly produced 6 different competing examples, including two
languishing patch proposals for the standard library.

I can always pick a random one and hope for the best, but I was hoping
someone here might have a tip for one that has been used and debugged
and is likely to work.

Regards,
Geoff Bache
  

What about

http://docs.python.org/library/threading.html#lock-objects

?

JM
--
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Geoff Bache
On Thu, Apr 28, 2011 at 4:28 PM, Jean-Michel Pichavant
jeanmic...@sequans.com wrote:
 Geoff Bache wrote:

 Hi all,

 I currently find myself needing a Python read-write lock. I note that
 there is none in the standard library, but googling python read-write
 lock quickly produced 6 different competing examples, including two
 languishing patch proposals for the standard library.

 I can always pick a random one and hope for the best, but I was hoping
 someone here might have a tip for one that has been used and debugged
 and is likely to work.

 Regards,
 Geoff Bache


 What about

 http://docs.python.org/library/threading.html#lock-objects

Those aren't read-write locks. They are basic locks, which don't
distinguish between readers and writers. I need to be able to lock
between reader and writer operations, without readers locking each
other out.

/Geoff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread D'Arcy J.M. Cain
On Thu, 28 Apr 2011 19:14:45 +0200
Geoff Bache geoff.ba...@gmail.com wrote:
 On Thu, Apr 28, 2011 at 4:28 PM, Jean-Michel Pichavant
 jeanmic...@sequans.com wrote:
  What about
 
  http://docs.python.org/library/threading.html#lock-objects
 
 Those aren't read-write locks. They are basic locks, which don't
 distinguish between readers and writers. I need to be able to lock
 between reader and writer operations, without readers locking each
 other out.

There really isn't any such thing as read-write locks.  In fact, the
term locks without any further explanation is pretty loose in any
case.  You can use the above method to implement your own locking
scheme.  However, that only works if your application is a single,
multi-threaded app.  Is that the case?  When I saw your original
question I thought that you needed something inter-process.  If so then
you need another scheme.

I think you have to first clarify your requirements and ask again.  I
have gleaned a little more information from your above response, you
don't require readers to be locked out during an update if I understand
the requirement.  There is still a lot of information missing.  For
example:

 - What is being read and written?  Files?
 - Is this a single multi-threaded app or multiple processes?
 - if multiple processes, can they be counted on to cooperate?
 - Do update requests need to be queued or is random availability OK?

Now, don't just answer the above questions. Try to start with that and
think about what other requirements you have.  The more information you
give us, the better the answer will be.  You may even find that locking
is not the actual answer you need.  People do have a tendency to offer
solutions when they think they are asking questions.  Don't pre-suppose
the answer.

http://www.catb.org/~esr/faqs/smart-questions.html is always a good
read in these situations.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Geoff Bache
On Thu, Apr 28, 2011 at 7:53 PM, D'Arcy J.M. Cain da...@druid.net wrote:
 On Thu, 28 Apr 2011 19:14:45 +0200
 Geoff Bache geoff.ba...@gmail.com wrote:
 On Thu, Apr 28, 2011 at 4:28 PM, Jean-Michel Pichavant
 jeanmic...@sequans.com wrote:
  What about
 
  http://docs.python.org/library/threading.html#lock-objects

 Those aren't read-write locks. They are basic locks, which don't
 distinguish between readers and writers. I need to be able to lock
 between reader and writer operations, without readers locking each
 other out.

 There really isn't any such thing as read-write locks.

Did you google it? I even provided the exact search terms to use in my
initial posting. It takes you straight to two standard library patch
proposals and four other solutions, all labelled this way (sometimes
reader-writer locks admittedly). That doesn't happen if it isn't a
standard problem.

I'm not looking for general advice on how to solve some specific
problem. I'm asking if anyone knows anything about the relative merits
of the above 6 solutions.

Regards,
Geoff Bache
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Ben Finney
Geoff Bache geoff.ba...@gmail.com writes:

 I currently find myself needing a Python read-write lock.

Please tell us what you mean by “read-write lock”.

 I note that there is none in the standard library, but googling
 python read-write lock quickly produced 6 different competing
 examples, including two languishing patch proposals for the standard
 library.

That's probably because the term isn't well defined. What is your
definition?

-- 
 \  “If you can't beat them, arrange to have them beaten.” —George |
  `\Carlin |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Ryan Kelly
On Thu, 2011-04-28 at 07:02 -0700, Geoff Bache wrote:
 Hi all,
 
 I currently find myself needing a Python read-write lock. I note that
 there is none in the standard library, but googling python read-write
 lock quickly produced 6 different competing examples, including two
 languishing patch proposals for the standard library.
 
 I can always pick a random one and hope for the best, but I was hoping
 someone here might have a tip for one that has been used and debugged
 and is likely to work.

I wrote and have used the SHLock class in threading2 which should do
what you need.  Don't know about likely to work but if it doesn't, I'd
like to hear about it so I can fix it :-)

  `pip install threading2`


  Cheers,

Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list