Code: Alles auswählen
account1.withdraw(amount)
account2.deposite(amount)
Stefan
Code: Alles auswählen
account1.withdraw(amount)
account2.deposite(amount)
Code: Alles auswählen
>>> import threading
>>> my_lock = threading.Lock()
>>> def my_global_function():
... my_lock.acquire()
... try:
... print "Schritt 1"
... print "Schritt 2"
... finally:
... my_lock.release()
...
Erfreulicherweise kann ein Lock auch als Context-Manager agieren und dadurch das `with`-Statement verwendet werden (Quelle):gerold hat geschrieben:Code: Alles auswählen
>>> import threading >>> my_lock = threading.Lock() >>> def my_global_function(): ... my_lock.acquire() ... try: ... print "Schritt 1" ... print "Schritt 2" ... finally: ... my_lock.release() ...
Code: Alles auswählen
from __future__ import with_statement
import threading
my_lock = threading.Lock()
def my_global_function():
with my_lock:
print "Schritt 1"
print "Schritt 2"
Code: Alles auswählen
>>> import threading
>>> my_lock = threading.Lock()
>>> def my_global_function():
... with my_lock:
... print "Schritt 1"
... print "Schritt 2"
Code: Alles auswählen
class Transaction(threading.local):
def owns(self, model):
return model._t_owner is self.thread
def get(self, model, name):
if name.startswith('_t_'):
return model.__dict__[name]
if self.owns(model):
return model._t_new[name]
return model._t_old[name]
Trellis ist tatsächlich ein interessanter Ansatz, aber ich finde da fehlt noch irgendwie ein konkreter Einsatzzweck wo man sagen könnte "Ha, dafür wäre Trellis optimal". Naja, wenn man vom CLOS kommt, dann wird man die Cells mögen, aber ich habe beim besten Willen nicht herausgefunden, wozu mir persönlich Trellis behilflich sein könnte.veers hat geschrieben:Trellis ist ein anderer Ansatz. Ich kam damit jedoch irgend wie nicht klar.