Ejemplo n.º 1
0
 def __init__(self):
     self.root = tkinter.Tk()
     self.root.title("Mandelbrot (Pyro multi CPU core version)")
     canvas = tkinter.Canvas(self.root,
                             width=res_x,
                             height=res_y,
                             bg="#000000")
     canvas.pack()
     self.img = tkinter.PhotoImage(width=res_x, height=res_y)
     canvas.create_image((res_x / 2, res_y / 2),
                         image=self.img,
                         state="normal")
     with locateNS() as ns:
         mandels = ns.list(metadata_any={"class:mandelbrot_calc_color"})
         mandels = list(mandels.items())
     print("{0} mandelbrot calculation servers found.".format(len(mandels)))
     if not mandels:
         raise ValueError(
             "launch at least one mandelbrot calculation server before starting this"
         )
     self.mandels = [uri for _, uri in mandels]
     self.pool = futures.ThreadPoolExecutor(max_workers=len(self.mandels))
     self.tasks = []
     self.start_time = time.time()
     for line in range(res_y):
         self.tasks.append(self.calc_new_line(line))
     self.root.after(100, self.draw_results)
     tkinter.mainloop()
Ejemplo n.º 2
0
 def unregister(self):
     try:
         ns = locateNS(self.ns_hostname)
         ns.remove(WORKPLACE + '.' + self.address)
         logger.debug(ns.list())
     except:
         logger.debug("could not locate nameserver")
Ejemplo n.º 3
0
 def unregister_agents(self):
     try:
         ns = locateNS(self.ns_hostname)
         for agent in self.__agents.values():
             ns.remove('%s.%s' % (AGENT, agent.address))
         logger.debug(ns.list())
     except:
         logger.debug("could not locate nameserver")
Ejemplo n.º 4
0
 def unregister(self):
     try:
         self.unregister_agents()
         ns = locateNS(self.ns_hostname)
         ns.remove(WORKPLACE + '.' + self.address)
         logger.debug(ns.list())
     except:
         logger.debug("could not locate nameserver")
Ejemplo n.º 5
0
 def unregister_agents(self):
     try:
         ns = locateNS(self.ns_hostname)
         for agent in self.__agents.values():
             ns.remove('%s.%s' % (AGENT, agent.address))
         logger.debug(ns.list())
     except:
         logger.debug("could not locate nameserver")
Ejemplo n.º 6
0
 def publish_agents(self):
     for agent in self.__agents.values():
         try:
             uri = self.daemon.register(agent)
             ns = locateNS(self.ns_hostname)
             ns.register('%s.%s' % (AGENT, agent.address), uri)
             logger.debug(ns.list())
         except:
             logger.debug("could not locate nameserver")
Ejemplo n.º 7
0
 def publish(self):
     if hasattr(self, "ns_hostname") and hasattr(self, "daemon"):
         uri = self.daemon.register(self)
         try:
             ns = locateNS(self.ns_hostname)
             ns.register(WORKPLACE + '.' + self.address, uri)
             logger.debug(ns.list())
         except:
             logger.debug("could not locate nameserver")
Ejemplo n.º 8
0
 def publish_agents(self):
     for agent in self.__agents.values():
         try:
             uri = self.daemon.register(agent)
             ns = locateNS(self.ns_hostname)
             ns.register('%s.%s' % (AGENT, agent.address), uri)
             logger.debug(ns.list())
         except:
             logger.debug("could not locate nameserver")
Ejemplo n.º 9
0
 def publish(self):
     if hasattr(self, "ns_hostname") and hasattr(self, "daemon"):
         uri = self.daemon.register(self)
         try:
             ns = locateNS(self.ns_hostname)
             ns.register(WORKPLACE + '.' + self.address, uri)
             logger.debug(ns.list())
             self.publish_agents()
         except:
             logger.debug("could not locate nameserver")
Ejemplo n.º 10
0
 def __init__(self):
     self.root = tkinter.Tk()
     self.root.title("Mandelbrot (Pyro multi CPU core version)")
     canvas = tkinter.Canvas(self.root, width=res_x, height=res_y, bg="#000000")
     canvas.pack()
     self.img = tkinter.PhotoImage(width=res_x, height=res_y)
     canvas.create_image((res_x/2, res_y/2), image=self.img, state="normal")
     with locateNS() as ns:
         mandels = ns.list(metadata_any={"class:mandelbrot_calc_color"})
         mandels = list(mandels.items())
     print("{0} mandelbrot calculation servers found.".format(len(mandels)))
     if not mandels:
         raise ValueError("launch at least one mandelbrot calculation server before starting this")
     self.mandels = [uri for _, uri in mandels]
     self.pool = futures.ThreadPoolExecutor(max_workers=len(self.mandels))
     self.tasks = []
     self.start_time = time.time()
     for line in range(res_y):
         self.tasks.append(self.calc_new_line(line))
     self.root.after(100, self.draw_results)
     tkinter.mainloop()
Ejemplo n.º 11
0
from Pyro4 import locateNS, Proxy
fr = Proxy(locateNS().lookup("frontend"))
for _ in range(100):
    while True:
        try:
            fr.add_rating(1, '1', 0)
            break
        except RuntimeError:
            pass
Ejemplo n.º 12
0
def get_servers():
    ns = locateNS(host=RoutesConfig.HOST, port=RoutesConfig.PORT)
    return ns.list('custom-route-')
Ejemplo n.º 13
0
import sys
from Pyro4 import naming, locateNS

if __name__ == "__main__":
    args = []
    flags = []
    if len(sys.argv)>1:
        for arg in sys.argv[1:]:
            if arg.startswith('--'): flags.append(arg[2:])
            elif arg=='-f': flags.append('force_restart')
            else: args.append(arg)
    try:
        ns = locateNS()
        sys.exit(-1)
    except:
        sys.exit(naming.main())
Ejemplo n.º 14
0
from constants.routes_config import RoutesConfig
from helpers.utils import generate_route, get_replica
from multicast import MultiCast
from Pyro4 import locateNS, Daemon
from Pyro4.errors import CommunicationError


if __name__ == "__main__":
    route = generate_route()
    server = MultiCast()

    try:
        server_copy = get_replica()
        if server_copy:
            server.overwrite_messages(server_copy.get_messages)
    except CommunicationError:
        pass

    with Daemon() as daemon:
        ns = locateNS(host=RoutesConfig.HOST, port=RoutesConfig.PORT)
        uri = daemon.register(server)
        servers = ns.list('custom-route-')
        ns.register(route, uri)
        print("Server running...")
        daemon.requestLoop()
        ns.remove(route, uri)
Ejemplo n.º 15
0
import sys
import random
import time
from Pyro4 import Proxy, locateNS

r = Proxy(locateNS().lookup("replica:%s" % sys.argv[1]))
t = {}
for i in range(100):
    while True:
        try:
            t = r.update(('U', (1, 1, random.choice([0, 1]))), t)
            time.sleep(random.random() / 100)
            break
        except RuntimeError:
            pass
Ejemplo n.º 16
0
import pprint
import sys
from Pyro4 import Proxy, locateNS

db = Proxy(locateNS().lookup("replica:%s" % sys.argv[1])).get_state()[1]

# convert to JSON friendly output
for movie in db["movies"].values():
    movie["genres"] = list(sorted(movie["genres"]))
for user_tags in db["tags"].values():
    for user_id, tags in user_tags.items():
        user_tags[user_id] = list(sorted(tags))

pprint.pprint(db, width=100)