Esempio n. 1
0
def test_cmdline_run(supervisor_args, worker_args, use_web_addr):
    new_isolation()
    sv_proc = w_procs = None
    try:
        env = os.environ.copy()
        env['MARS_CPU_TOTAL'] = '2'

        sv_args = _reload_args(supervisor_args)
        sv_proc = subprocess.Popen(sv_args, env=env)

        oscar_port = _get_labelled_port('supervisor', create=False)
        if not oscar_port:
            oscar_ep = _wait_supervisor_ready(sv_proc)
        else:
            oscar_ep = f'127.0.0.1:{oscar_port}'

        if use_web_addr:
            host = oscar_ep.rsplit(':', 1)[0]
            api_ep = f'http://{host}:{_get_labelled_port("web", create=False)}'
        else:
            api_ep = oscar_ep

        w_procs = [subprocess.Popen(
            _reload_args(worker_args), env=env) for _ in range(2)]
        _wait_worker_ready(oscar_ep, w_procs)

        new_session(api_ep)
        data = np.random.rand(10, 10)
        res = mt.tensor(data, chunk_size=5).sum().execute().fetch()
        np.testing.assert_almost_equal(res, data.sum())
    finally:
        ep_file_name = OscarCommandRunner._build_endpoint_file_path(pid=sv_proc.pid)
        try:
            os.unlink(ep_file_name)
        except OSError:
            pass

        w_procs = w_procs or []
        for proc in w_procs + [sv_proc]:
            if not proc:
                continue
            proc.terminate()
            try:
                proc.wait(3)
            except subprocess.TimeoutExpired:
                kill_process_tree(proc.pid)

        stop_isolation()
Esempio n. 2
0
 def kill_process_tree(self, proc, intentional=True):
     if intentional:
         self.intentional_death_pids.add(proc.pid)
     kill_process_tree(proc.pid)