print "Philosopher %i thinking" % (i, ) while random.random() < 0.6: time.sleep(1) def eat(i): print "Philosopher %i eating" % (i, ) while random.random() < 0.6: time.sleep(1) # create the philosophers import sys if len(sys.argv) == 1: ts = linda.TupleSpace() import os for i in range(number): if os.fork() == 0: os.execlp("./philosophers.py", "./philosophers.py", str(i)) linda.uts._out((ts, )) ts._out(("chopstick", i)) ts._out(("room ticket", )) else: ts = linda.uts._in((linda.TupleSpace, ))[0] Philosopher(int(sys.argv[1]))
#!/usr/bin/python import sys import linda linda.connect() prime_ts = linda.TupleSpace() linda.uts._out(("prime_ts", prime_ts)) work_ts = linda.TupleSpace() for i in range(int(sys.argv[1])): linda.uts._out(("work_ts", work_ts)) work_ts._out((2, 0, 0)) for i in range(3, 1000): work_ts._out((i, 2, i - 3)) while True: tup = prime_ts._inp((int, )) if tup is None: break print tup[0]
import linda linda.connect() # Exemplo de arquivo que escreve e le do tuplespace blog = linda.TupleSpace() linda.universe._out(("Blog", blog)) blog = linda.universe._rd(("Blog", linda.TupleSpace))[1] blog._out(("bob", "distsys", "I am studying chap 2")) blog._out(("bob", "distsys", "The linda example's pretty simple")) blog._out(("bob", "distsys", "A new message!")) blog._out(("bob", "gtcn", "Cool book!")) t1 = blog._rd(("bob", "distsys", str)) # t2 = blog._rd(("alice","gtcn",str)) # t3 = blog._rd(("bob","gtcn",str)) print(t1) blog._in(("bob", "distsys", "I am studying chap 2")) t1 = blog._rd(("bob", "distsys", str)) print(t1) # print(t2) # print(t3)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with PyLinda; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import linda linda.connect() import sys MaxIters = 256 * 256 - 1 if len(sys.argv) > 1 and sys.argv[1] == "master": out = linda.TupleSpace() pix = linda.TupleSpace() linda.uts._out(("out", out)) linda.uts._out(("pix", pix)) width, height = 80, 80 left, right, top, bottom = -2.0, 1.0, -1.0, 1.0 rls = (right - left) / width bts = (bottom - top) / height ylist = range(height) * width xlist = range(width) * height xlist.sort()
bloglinda._out((user, args["topic"], args["message"])) # status 201 = created return 201 def delete(self, user): parser = reqparse.RequestParser() parser.add_argument("topic") parser.add_argument("menssage") args = parser.parse_args() bloglinda._in((user, args["topic"], args["menssage"])) #status 200 = ok return "Message Deleted", 200 if __name__ == "__main__": app = Flask(__name__) api = Api(app) linda.connect() bloglinda = linda.TupleSpace() linda.universe._out(("Blog Linda", bloglinda)) api.add_resource(MicroBlog, "/blog/<string:user>") app.run(debug = True)