[Python-Dev] New PEP: 319

Roman Suzi rnd@onego.ru
2003年6月16日 10:43:47 +0400 (MSD)


On 2003年6月16日, Michel Pelletier wrote:
> > On 2003年6月16日, Michel Pelletier wrote:
> >
> >> def __init__(self):
> >> self.counter = 0
> >>
> >> def increment(self):
> >> synchronize:
> >> self.counter += 1
> >
> > What about just adding a parameter to try operator?
> >
> > def increment(self):
> > try self.counter_lock:
> > self.counter += 1
>> Because I would like to remove the user-visible lock entirely. Although
> your idea is similar to PEP 310, which proposes a new keyword "with". I
> think using the try keyword for this is inapropriate.

But is it such a good idea to do? What if critical section is at two or
more different places at once? How will you deal with
 def increment(self):
 try self.counter_lock:
 self.counter += 1
 def decrement(self):
 try self.counter_lock:
 self.counter -= 1
(Suppose, it's not simple or elegant to do it in one place:
 def change(self, delta=1):
 try self.counter_lock:
 self.counter += delta
)
As for with, it could be added as follows:
 try with lock:
 lalalala
 
> -Michel

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd@onego.ru -
 

AltStyle によって変換されたページ (->オリジナル) /