def _jobresult(self, jobid, json=True, headers=None):
failures = <NUM_LIT:0><EOL>total_time = self.job_timeout or <NUM_LIT:2>**<NUM_LIT:30><EOL>remaining = timedelta(seconds=total_time)<EOL>endtime = datetime.now() + remaining<EOL>while remaining.total_seconds() > <NUM_LIT:0>:<EOL><INDENT>timeout = max(min(self.timeout, remaining.total_seconds()), <NUM_LIT:1>)<EOL>try:<EOL><INDENT>kind, params = self._prepare_request('<STR_LIT>',<EOL>jobid=jobid)<EOL>transform(params)<EOL>params['<STR_LIT>'] = self._sign(params)<EOL>req = requests.Request(self.method,<EOL>self.endpoint,<EOL>headers=headers,<EOL>**{kind: params})<EOL>prepped = req.prepare()<EOL>if self.trace:<EOL><INDENT>print(prepped.method, prepped.url, file=sys.stderr)<EOL>if prepped.headers:<EOL><INDENT>print(prepped.headers, "<STR_LIT:\n>", file=sys.stderr)<EOL><DEDENT>if prepped.body:<EOL><INDENT>print(prepped.body, file=sys.stderr)<EOL><DEDENT>else:<EOL><INDENT>print(file=sys.stderr)<EOL><DEDENT><DEDENT>with requests.Session() as session:<EOL><INDENT>response = session.send(prepped,<EOL>timeout=timeout,<EOL>verify=self.verify,<EOL>cert=self.cert)<EOL><DEDENT>j = self._response_value(response, json)<EOL>if self.trace:<EOL><INDENT>print(response.status_code, response.reason,<EOL>file=sys.stderr)<EOL>headersTrace = "<STR_LIT:\n>".join(<EOL>"<STR_LIT>".format(k, v)<EOL>for k, v in response.headers.items())<EOL>print(headersTrace, "<STR_LIT:\n>", file=sys.stderr)<EOL>print(response.text, "<STR_LIT:\n>", file=sys.stderr)<EOL><DEDENT>failures = <NUM_LIT:0><EOL>if j['<STR_LIT>'] != PENDING:<EOL><INDENT>if j['<STR_LIT>'] or j['<STR_LIT>'] != SUCCESS:<EOL><INDENT>raise CloudStackException("<STR_LIT>",<EOL>response=response)<EOL><DEDENT>if '<STR_LIT>' not in j:<EOL><INDENT>raise CloudStackException("<STR_LIT>",<EOL>response=response)<EOL><DEDENT>return j['<STR_LIT>']<EOL><DEDENT><DEDENT>except CloudStackException:<EOL><INDENT>raise<EOL><DEDENT>except Exception as e:<EOL><INDENT>failures += <NUM_LIT:1><EOL>if failures > <NUM_LIT:10>:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>time.sleep(self.poll_interval)<EOL>remaining = endtime - datetime.now()<EOL><DEDENT>if response:<EOL><INDENT>response.status_code = <NUM_LIT><EOL><DEDENT>raise CloudStackException("<STR_LIT>",<EOL>jobid,<EOL>response=response)<EOL>
Poll the async job result.

        To be run via in a Thread, the result is put within
        the result list which is a hack.