Esempio n. 1
0
    def _setUpPyro(self):
        global _pyomo_ns_port
        global _pyomo_ns_process
        global _dispatch_srvr_port
        global _dispatch_srvr_process
        global _taskworker_processes
        if _pyomo_ns_process is None:
            _pyomo_ns_process, _pyomo_ns_port = \
                _get_test_nameserver(ns_host=_pyomo_ns_host)
        assert _pyomo_ns_process is not None
        if _dispatch_srvr_process is None:
            _dispatch_srvr_process, _dispatch_srvr_port = \
                _get_test_dispatcher(ns_host=_pyomo_ns_host,
                                     ns_port=_pyomo_ns_port)
        assert _dispatch_srvr_process is not None
        class_name, test_name = self.id().split('.')[-2:]
        if len(_taskworker_processes) == 0:
            for i in range(3):
                outname = os.path.join(
                    thisdir, class_name + "." + test_name +
                    ".scenariotreeserver_" + str(i + 1) + ".out")
                self._tempfiles.append(outname)
                with open(outname, "w") as f:
                    _taskworker_processes.append(
                        subprocess.Popen(["scenariotreeserver", "--traceback"] + \
                                         (["--verbose"] if _run_verbose else []) + \
                                         ["--pyro-host="+str(_pyomo_ns_host)] + \
                                         ["--pyro-port="+str(_pyomo_ns_port)],
                                         stdout=f,
                                         stderr=subprocess.STDOUT))

            time.sleep(2)
            [_poll(proc) for proc in _taskworker_processes]
Esempio n. 2
0
def _setUpPyro():
    global _pyomo_ns_port
    global _pyomo_ns_process
    global _dispatch_srvr_port
    global _dispatch_srvr_process
    global _taskworker_processes
    if _pyomo_ns_process is None:
        _pyomo_ns_process, _pyomo_ns_port = \
            _get_test_nameserver(ns_host=_pyomo_ns_host)
    assert _pyomo_ns_process is not None
    if _dispatch_srvr_process is None:
        _dispatch_srvr_process, _dispatch_srvr_port = \
            _get_test_dispatcher(ns_host=_pyomo_ns_host,
                                 ns_port=_pyomo_ns_port)
    assert _dispatch_srvr_process is not None
    if len(_taskworker_processes) == 0:
        for i in range(3):
            outname = os.path.join(thisdir,
                                   "TestCapture_scenariotreeserver_" + \
                                   str(i+1) + ".out")
            with open(outname, "w") as f:
                _taskworker_processes.append(
                    subprocess.Popen(["scenariotreeserver", "--traceback"] + \
                                     ["--import-module="+thisfile] + \
                                     (["--verbose"] if _run_verbose else []) + \
                                     ["--pyro-host="+str(_pyomo_ns_host)] + \
                                     ["--pyro-port="+str(_pyomo_ns_port)],
                                     stdout=f,
                                     stderr=subprocess.STDOUT))
        time.sleep(2)
        [_poll(proc) for proc in _taskworker_processes]
Esempio n. 3
0
 def setUp(self):
     self._tempfiles = []
     self._setUpPyro()
     [_poll(proc) for proc in _taskworker_processes]
     self.options = {}
     self.options['--scenario-tree-manager'] = 'pyro'
     self.options['--pyro-host'] = 'localhost'
     self.options['--pyro-port'] = _pyomo_ns_port
     self.options['--pyro-required-scenariotreeservers'] = 3
Esempio n. 4
0
 def _init(self, factory):
     _setUpPyro()
     [_poll(proc) for proc in _taskworker_processes]
     options = ScenarioTreeManagerClientPyro.register_options()
     options.pyro_port = _pyomo_ns_port
     options.pyro_required_scenariotreeservers = 3
     options.pyro_handshake_at_startup = True
     sp = ScenarioTreeManagerClientPyro(options, factory=factory)
     sp.initialize()
     return sp
Esempio n. 5
0
 def _run_cmd_with_pyro(self, cmd, num_servers):
     ns_host = '127.0.0.1'
     ns_process = None
     dispatcher_process = None
     scenariotreeserver_processes = []
     try:
         ns_process, ns_port = \
             _get_test_nameserver(ns_host=ns_host)
         self.assertNotEqual(ns_process, None)
         dispatcher_process, dispatcher_port = \
             _get_test_dispatcher(ns_host=ns_host,
                                  ns_port=ns_port)
         self.assertNotEqual(dispatcher_process, None)
         scenariotreeserver_processes = []
         class_name, test_name = self.id().split('.')[-2:]
         for i in range(num_servers):
             outname = os.path.join(thisdir,
                                    class_name+"."+test_name+".scenariotreeserver_"+str(i+1)+".out")
             self._tempfiles.append(outname)
             with open(outname, "w") as f:
                 scenariotreeserver_processes.append(
                     subprocess.Popen(["scenariotreeserver", "--traceback"] + \
                                      ["--pyro-host="+str(ns_host)] + \
                                      ["--pyro-port="+str(ns_port)],
                                      stdout=f,
                                      stderr=subprocess.STDOUT))
         cmd.append("--scenario-tree-manager=pyro")
         cmd.append("--pyro-host="+str(ns_host))
         cmd.append("--pyro-port="+str(ns_port))
         time.sleep(2)
         [_poll(proc) for proc in scenariotreeserver_processes]
         self._run_cmd(cmd)
     finally:
         _kill(ns_process)
         _kill(dispatcher_process)
         [_kill(proc) for proc in scenariotreeserver_processes]
         if os.path.exists(os.path.join(thisdir,'Pyro_NS_URI')):
             try:
                 os.remove(os.path.join(thisdir,'Pyro_NS_URI'))
             except OSError:
                 pass
Esempio n. 6
0
 def test_solve_distributed(self):
     ns_host = '127.0.0.1'
     ns_process = None
     dispatcher_process = None
     scenariotreeserver_processes = []
     try:
         ns_process, ns_port = \
             _get_test_nameserver(ns_host=ns_host)
         self.assertNotEqual(ns_process, None)
         dispatcher_process, dispatcher_port = \
             _get_test_dispatcher(ns_host=ns_host,
                                  ns_port=ns_port)
         self.assertNotEqual(dispatcher_process, None)
         scenariotreeserver_processes = []
         class_name, test_name = self.id().split('.')[-2:]
         for i in range(3):
             outname = os.path.join(thisdir,
                                    class_name+"."+test_name+".scenariotreeserver_"+str(i+1)+".out")
             self._tempfiles.append(outname)
             with open(outname, "w") as f:
                 scenariotreeserver_processes.append(
                     subprocess.Popen(["scenariotreeserver", "--traceback"] + \
                                      ["--pyro-host="+str(ns_host)] + \
                                      ["--pyro-port="+str(ns_port)],
                                      stdout=f,
                                      stderr=subprocess.STDOUT))
         cmd = [sys.executable, join(examples_dir, 'solve_distributed.py'), str(ns_port)]
         time.sleep(2)
         [_poll(proc) for proc in scenariotreeserver_processes]
         self._run_cmd(cmd)
     finally:
         _kill(ns_process)
         _kill(dispatcher_process)
         [_kill(proc) for proc in scenariotreeserver_processes]
         if os.path.exists(os.path.join(thisdir,'Pyro_NS_URI')):
             try:
                 os.remove(os.path.join(thisdir,'Pyro_NS_URI'))
             except OSError:
                 pass
     self._cleanup()