Re: [Python-Dev] Proposed addition to threading module - released

2006-04-24 Thread Nick Coghlan
Martin v. Löwis wrote: Nick Coghlan wrote: Do we want to add a released context manager to the threading module for 2.5? I don't think that should be added. I would consider it a dangerous programming style: if the lock merely doesn't need to be held (i.e. if it isn't necessary, but

Re: [Python-Dev] Proposed addition to threading module - released

2006-04-24 Thread Guido van Rossum
On 4/23/06, Martin v. Löwis [EMAIL PROTECTED] wrote: Nick Coghlan wrote: Do we want to add a released context manager to the threading module for 2.5? I don't think that should be added. I would consider it a dangerous programming style: if the lock merely doesn't need to be held (i.e. if

Re: [Python-Dev] Proposed addition to threading module - released

2006-04-24 Thread Tim Peters
[Guido] Actually, what Nick describes is *exactly* how one should write code using a condition variable: LOCK while nothing to do: UNLOCK wait for the condition variable (or sleep, or whatever) LOCK # here we have something to do with the lock held remove the

Re: [Python-Dev] Proposed addition to threading module - released

2006-04-24 Thread Martin v. Löwis
Guido van Rossum wrote: Actually, what Nick describes is *exactly* how one should write code using a condition variable: LOCK while nothing to do: UNLOCK wait for the condition variable (or sleep, or whatever) LOCK # here we have something to do with the lock held

Re: [Python-Dev] Proposed addition to threading module - released

2006-04-24 Thread Martin v. Löwis
Tim Peters wrote: Does with cv: work to replace the outer (== only) acquire/try/finally/release dance? Indeed it does - although implemented in a somewhat convoluted way: A lock *is* a context (or is that context manager), i.e. it implements def __context__(self): return self

Re: [Python-Dev] Proposed addition to threading module - released

2006-04-24 Thread Guido van Rossum
On 4/24/06, Martin v. Löwis [EMAIL PROTECTED] wrote: Tim Peters wrote: Does with cv: work to replace the outer (== only) acquire/try/finally/release dance? Indeed it does - although implemented in a somewhat convoluted way: A lock *is* a context (or is that context manager), i.e.

Re: [Python-Dev] Proposed addition to threading module - released

2006-04-24 Thread Martin v. Löwis
Guido van Rossum wrote: Tim is right, the UNLOCK/LOCK part is implied in the wait() call. However, the wait() implementation really *does* provide a use case for the primitive operation that Nick proposed, and it can't be refactored to remove the pattern Martin disapproves of (though of

[Python-Dev] Proposed addition to threading module - released

2006-04-23 Thread Nick Coghlan
Do we want to add a released context manager to the threading module for 2.5? It was mentioned using the name unlocked in PEP 343, but never spelt out: class released(object): def __init__(self, lock): self.lock = lock def __enter__(self): self.lock.release() def