Exemple #1
0
    def test_06_blocking_methods(self):
        future = Future(self.f.future_create(ffi.NULL, ffi.NULL))

        self.assertFalse(future.is_ready())
        with self.assertRaises(EnvironmentError) as cm:
            future.wait_for(timeout=0)
        self.assertEqual(cm.exception.errno, errno.ETIMEDOUT)

        future.pimpl.fulfill(ffi.NULL, ffi.NULL)
        self.assertTrue(future.is_ready())
        try:
            future.wait_for(0)
        except EnvironmentError as e:
            self.fail("future.wait_for raised an unexpected exception: {}".format(e))
Exemple #2
0
def cancel_async(flux_handle, jobid, reason=None):
    """Cancel a pending or or running job asynchronously

    :param flux_handle: handle for Flux broker from flux.Flux()
    :type flux_handle: Flux
    :param jobid: the job ID of the job to cancel
    :returns: a Future
    :rtype: Future

    """
    if not reason:
        reason = ffi.NULL
    return Future(RAW.cancel(flux_handle, int(jobid), reason))
Exemple #3
0
def kill_async(flux_handle, jobid, signum=None):
    """Send a signal to a running job asynchronously

    :param flux_handle: handle for Flux broker from flux.Flux()
    :type flux_handle: Flux
    :param jobid: the job ID of the job to kill
    :param signum: signal to send (default SIGTERM)
    :returns: a Future
    :rtype: Future
    """
    if not signum:
        signum = signal.SIGTERM
    return Future(RAW.kill(flux_handle, int(jobid), signum))
Exemple #4
0
def submit_async(flux_handle,
                 jobspec,
                 priority=lib.FLUX_JOB_PRIORITY_DEFAULT,
                 flags=0):
    if isinstance(jobspec, six.text_type):
        jobspec = jobspec.encode("utf-8")
    elif jobspec is None or jobspec == ffi.NULL:
        # catch this here rather than in C for a better error message
        raise EnvironmentError(errno.EINVAL, "jobspec must not be None/NULL")
    elif not isinstance(jobspec, six.binary_type):
        raise TypeError("jobpsec must be a string (either binary or unicode)")

    future_handle = RAW.submit(flux_handle, jobspec, priority, flags)
    return Future(future_handle)
Exemple #5
0
def cancel_async(flux_handle: Flux,
                 jobid: Union[JobID, int],
                 reason: Optional[str] = None):
    """Cancel a pending or or running job asynchronously

    Arguments:
        flux_handle: handle for Flux broker from flux.Flux()
        jobid: the job ID of the job to cancel
        reason: the textual reason associated with the cancelation

    Returns:
        Future: a future fulfilled when the cancelation completes
    """
    if not reason:
        reason = ffi.NULL
    return Future(RAW.cancel(flux_handle, int(jobid), reason))
Exemple #6
0
    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()
Exemple #8
0
 def service_unregister(self, name):
     return Future(self.flux_service_unregister(name))