def do_work(job):
tstart = time.perf_counter()
status_code = None
timeout = False
connection_error = False
expect_not_present = False
try:
result = requests.get(job.get('url'), timeout=job.get('timeout'))
status_code = result.status_code
if job.get('expect'):
if job.get('expect') not in result.text:
expect_not_present = True
except ReadTimeout:
timeout = True
except socket_error:
connection_error = True
return {'status_code': status_code, 'ms': (time.perf_counter()-tstart)*1000, 'timeout': timeout,
'connection_error': connection_error,
'tstart': tstart, 'tstop': time.perf_counter(), 'expect_not_present': expect_not_present}
评论列表
文章目录