示例#1
0
    def wait(jobId, timeout=-1):
        """
        Wait for a job with jobId to finish execution or fail.

        :Parameters:
          `jobId` : str
            The job id to wait completion for.

            If the special string, `Session.JOB_IDS_SESSION_ANY`, is provided
            as the jobId, this routine will wait for any job from the session
          `timeout` : float
            The timeout value is used to specify the desired behavior when a
            result is not immediately available.

            The value `Session.TIMEOUT_WAIT_FOREVER` may be specified to wait
            indefinitely for a result. The value `Session.TIMEOUT_NO_WAIT` may
            be specified to return immediately if no result is
            available. Alternatively, a number of seconds may be specified to
            indicate how long to wait for a result to become available

        This routine is modeled on the wait3 POSIX routine. If the call exits
        before timeout, either the job has been waited on successfully or
        there was an interrupt. If the invocation exits on timeout, an
        `ExitTimeoutException` is thrown. The caller should check system time
        before and after this call in order to be sure how much time has
        passed.  The routine reaps job data records on a successful call, so
        any subsequent calls to wait() will fail, throwing an
        `InvalidJobException`, meaning that the job's data record has been
        already reaped.  This exception is the same as if the job were
        unknown. (The only case where wait() can be successfully called on a
        single job more than once is when the previous call to wait() timed
        out before the job finished.)
        """
        stat = c_int()
        jid_out = create_string_buffer(128)
        rusage = pointer(POINTER(drmaa_attr_values_t)())
        if isinstance(jobId, str):
            jobId = jobId.encode(ENCODING)
        c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout,
          rusage)
        res_usage = adapt_rusage(rusage)
        exited = c_int()
        c(drmaa_wifexited, byref(exited), stat)
        aborted = c_int()
        c(drmaa_wifaborted, byref(aborted), stat)
        signaled = c_int()
        c(drmaa_wifsignaled, byref(signaled), stat)
        coredumped = c_int()
        if exited.value == 0:
            c(drmaa_wcoredump, byref(coredumped), stat)
        exit_status = c_int()
        c(drmaa_wexitstatus, byref(exit_status), stat)
        term_signal = create_string_buffer(SIGNAL_BUFFER)
        if signaled.value == 1:
            c(drmaa_wtermsig, term_signal, sizeof(term_signal), stat)
        return JobInfo(jid_out.value.decode(), bool(exited), bool(signaled),
                       term_signal.value.decode(), bool(coredumped),
                       bool(aborted), int(exit_status.value), res_usage)
示例#2
0
    def wait(jobId, timeout=-1):
        """
        Wait for a job with jobId to finish execution or fail.

        :Parameters:
          `jobId` : str
            The job id to wait completion for.

            If the special string, `Session.JOB_IDS_SESSION_ANY`, is provided
            as the jobId, this routine will wait for any job from the session
          `timeout` : float
            The timeout value is used to specify the desired behavior when a
            result is not immediately available.

            The value `Session.TIMEOUT_WAIT_FOREVER` may be specified to wait
            indefinitely for a result. The value `Session.TIMEOUT_NO_WAIT` may
            be specified to return immediately if no result is
            available. Alternatively, a number of seconds may be specified to
            indicate how long to wait for a result to become available

        This routine is modeled on the wait3 POSIX routine. If the call exits
        before timeout, either the job has been waited on successfully or
        there was an interrupt. If the invocation exits on timeout, an
        `ExitTimeoutException` is thrown. The caller should check system time
        before and after this call in order to be sure how much time has
        passed.  The routine reaps job data records on a successful call, so
        any subsequent calls to wait() will fail, throwing an
        `InvalidJobException`, meaning that the job's data record has been
        already reaped.  This exception is the same as if the job were
        unknown. (The only case where wait() can be successfully called on a
        single job more than once is when the previous call to wait() timed
        out before the job finished.)
        """
        stat = c_int()
        jid_out = create_string_buffer(128)
        rusage = pointer(POINTER(drmaa_attr_values_t)())
        if isinstance(jobId, str):
            jobId = jobId.encode(ENCODING)
        c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout,
          rusage)
        res_usage = adapt_rusage(rusage)
        exited = c_int()
        c(drmaa_wifexited, byref(exited), stat)
        aborted = c_int()
        c(drmaa_wifaborted, byref(aborted), stat)
        signaled = c_int()
        c(drmaa_wifsignaled, byref(signaled), stat)
        coredumped = c_int()
        c(drmaa_wcoredump, byref(coredumped), stat)
        exit_status = c_int()
        c(drmaa_wexitstatus, byref(exit_status), stat)
        term_signal = create_string_buffer(SIGNAL_BUFFER)
        c(drmaa_wtermsig, term_signal, sizeof(term_signal), stat)
        return JobInfo(jid_out.value.decode(), bool(exited), bool(signaled),
                       term_signal.value.decode(), bool(coredumped),
                       bool(aborted), int(exit_status.value), res_usage)