def test_08_future_from_future(self): orig_fut = Future(self.f.future_create(ffi.NULL, ffi.NULL)) new_fut = Future(orig_fut) self.assertFalse(new_fut.is_ready()) orig_fut.pimpl.fulfill(ffi.NULL, ffi.NULL) self.assertTrue(new_fut.is_ready()) orig_fut = self.f.rpc("broker.ping", payload=self.ping_payload) new_fut = Future(orig_fut) del orig_fut resp_payload = new_fut.get() # Future's `get` returns `None`, so just test that it is fulfilled self.assertTrue(new_fut.is_ready()) orig_fut = self.f.rpc("foo.bar") new_fut = Future(orig_fut) del orig_fut with self.assertRaises(EnvironmentError): resp_payload = new_fut.get()
import flux from flux.constants import FLUX_MSGTYPE_REQUEST from flux.future import Future parser = argparse.ArgumentParser() parser.add_argument('--fail', action='store_true') args = parser.parse_args() def validate_cb(fh, t, msg, arg): payload = {"success": not args.fail} if args.fail: payload['errstr'] = "Failed for test purposes" fh.respond(msg, payload) print(f"Responded to vlidation request with {payload}") fh.reactor_stop() fh = flux.Flux() service_reg_fut = Future(fh.service_register("dws")) watcher = fh.msg_watcher_create(validate_cb, FLUX_MSGTYPE_REQUEST, "dws.validate") watcher.start() service_reg_fut.get() print("DWS service registered") fh.reactor_run() watcher.stop() watcher.destroy()