def test_15_job_cancel(self): self.sleep_jobspec = JobspecV1.from_command(["sleep", "1000"]) jobid = job.submit(self.fh, self.sleep_jobspec, waitable=True) job.cancel(self.fh, jobid) fut = job.wait_async(self.fh, jobid=jobid).wait_for(5.0) return_id, success, errmsg = fut.get_status() self.assertEqual(return_id, jobid) self.assertFalse(success)
def test_16_job_kill(self): self.sleep_jobspec = JobspecV1.from_command(["sleep", "1000"]) jobid = job.submit(self.fh, self.sleep_jobspec, waitable=True) # Wait for shell to fully start to avoid delay in signal job.event_wait(self.fh, jobid, name="start") job.event_wait( self.fh, jobid, name="shell.start", eventlog="guest.exec.eventlog" ) job.kill(self.fh, jobid, signum=signal.SIGKILL) fut = job.wait_async(self.fh, jobid=jobid).wait_for(5.0) return_id, success, errmsg = fut.get_status() self.assertEqual(return_id, jobid) self.assertFalse(success)
from flux import job from flux.job import JobspecV1 import sys if len(sys.argv) != 2: njobs = 10 else: njobs = int(sys.argv[1]) # Open connection to broker h = flux.Flux() # Submit njobs test jobs jobspec = JobspecV1.from_command(["/bin/true"]) jobs = [] for i in range(njobs): jobid = job.submit(h, jobspec, waitable=True) print("submit: {} /bin/true".format(jobid)) jobs.append(jobid) # Async wait which we immediately abandon # Do half with jobid, half without to cover both disconnect loops # N.B. most likely this leaves some zombies so clean up after for i in range(njobs): if i < njobs / 2: f = job.wait_async(h, jobs[i]) else: f = job.wait_async(h) # vim: tabstop=4 shiftwidth=4 expandtab