Ejemplo n.º 1
0
 def __init__(self, forks=None, store=None, name=None):
     super(Philosopher, self).__init__()
     if forks:
         self.forks = forks
     else:
         self.forks = ["fork.1", "fork.2"]
     if store:
         self.store = store
     else:
         self.store = Store()
     if name:
         self.name = name
     else:
         self.name = id(self)
Ejemplo n.º 2
0
 def __init__ (self,forks = None, store=None,name=None):
     super(Philosopher,self).__init__()
     if forks:
         self.forks = forks
     else:
         self.forks = ["fork.1", "fork.2"]
     if store:
         self.store = store
     else:
         self.store = Store()
     if name:
         self.name = name
     else:
         self.name = id(self)
Ejemplo n.º 3
0
class Philosopher(Thread):
    def __init__(self, forks=None, store=None, name=None):
        super(Philosopher, self).__init__()
        if forks:
            self.forks = forks
        else:
            self.forks = ["fork.1", "fork.2"]
        if store:
            self.store = store
        else:
            self.store = Store()
        if name:
            self.name = name
        else:
            self.name = id(self)

    def getforks(self):
        gotforks = False
        while not gotforks:
            try:
                X = self.store.using(*self.forks)
                if all([X[fork].value for fork in self.forks], None):
                    for fork in self.forks:
                        X[fork].value = self.name
                    X.commit()
                    gotforks = True
                else:
                    time.sleep(random.random())
            except ConcurrentUpdate:
                time.sleep(random.random())
            except BusyRetry:
                time.sleep(random.random())
        print("Got forks!", self.name, self.forks)
        return X

    def releaseforks(self, X):
        print("releasing forks", self.name)
        for fork in self.forks:
            X[fork].value = None
        X.commit()

    def run(self):
        while 1:
            X = self.getforks()
            time.sleep(0.2)
            self.releaseforks(X)
            time.sleep(0.3 + random.random())
Ejemplo n.º 4
0
class Philosopher(Thread):
    def __init__ (self,forks = None, store=None,name=None):
        super(Philosopher,self).__init__()
        if forks:
            self.forks = forks
        else:
            self.forks = ["fork.1", "fork.2"]
        if store:
            self.store = store
        else:
            self.store = Store()
        if name:
            self.name = name
        else:
            self.name = id(self)
    
    def getforks(self):
        gotforks = False
        while not gotforks:
            try:
                X = self.store.using(*self.forks)
                if all([ X[fork].value for fork in self.forks], None):
                    for fork in self.forks:
                        X[fork].value = self.name
                    X.commit()
                    gotforks = True
                else:
                    time.sleep(random.random())
            except ConcurrentUpdate:
                time.sleep(random.random())
            except BusyRetry:
                time.sleep(random.random())
        print ("Got forks!", self.name, self.forks)
        return X

    def releaseforks(self,X):
        print ("releasing forks", self.name)
        for fork in self.forks:
            X[fork].value = None
        X.commit()

    def run(self):
        while 1:
            X = self.getforks()
            time.sleep(0.2)
            self.releaseforks(X)
            time.sleep(0.3+random.random())
Ejemplo n.º 5
0
                time.sleep(random.random())
            except BusyRetry:
                time.sleep(random.random())
        print("Got forks!", self.name, self.forks)
        return X

    def releaseforks(self, X):
        print("releasing forks", self.name)
        for fork in self.forks:
            X[fork].value = None
        X.commit()

    def run(self):
        while 1:
            X = self.getforks()
            time.sleep(0.2)
            self.releaseforks(X)
            time.sleep(0.3 + random.random())


S = Store()
N = 5
for i in range(1, N):
    Philosopher(store=S, forks=["fork.%d" % i,
                                "fork.%d" % (i + 1)], name=i).start()

Philosopher(store=S, forks=["fork.%d" % N, "fork.%d" % 1]).start()

while 1:
    time.sleep(100)
Ejemplo n.º 6
0
from Kamaelia.Util.Backplane import *
from Kamaelia.Apps.Whiteboard.Canvas import Canvas
from Kamaelia.Chassis.Graphline import Graphline
from Kamaelia.UI.Pygame.Display import PygameDisplay
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Apps.SpeakNLearn.Gestures.StrokeRecogniser import StrokeRecogniser
from Kamaelia.UI.Pygame.Text import TextDisplayer, Textbox
from Kamaelia.Apps.Whiteboard.Routers import TwoWaySplitter
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.UnixProcess import UnixProcess


from Kamaelia.Apps.SpeakNLearn.Gestures.Pen import Pen
from Axon.STM import Store

SpokenStore = Store()

class aggregator(Axon.Component.component):
    def main(self):
        while True:
            while self.dataReady("inbox"):
                data = self.recv("inbox")
                if len(data) == 0:
                    continue
                if data == "\\":
                    data = data[1:]
                    self.send("\x08", "outbox")
                    continue

                for C in data:
                    self.send(C, "outbox") # sent