如果查询除外

时间:2016-04-03 12:46:09

标签: python time python-requests response-time

我正在尝试创建一个功能,我有三个不同的级别;响应时间长,响应时间短,响应时间短。对于最后一个,它应该是两个值之间的间隔,例如在1到1.5秒之间。我可以使用SQL> create database test 2 Datafile '/opt/oradata/test/system01.dbf' size 10M 3 Sysaux datafile '/opt/oradata/test/sysaux01.dbf' size 10M 4 Logfile '/opt/oradata/test/redo01.log' size 10M, 5 '/opt/oradata/test/redo02.log' size 10M 6 Undo tablespace undotbs1 7 Datafile '/opt/oradata/test/undo01.dbf' size 10M 8 Default temporary tablespace temp 9 Tempfile '/opt/oradata/test/temp01.dbf' size 10M; Error: SQL> / create database test * ERROR at line 1: ORA-01092: ORACLE instance terminated. Disconnection forced ORA-01501: CREATE DATABASE failed ORA-01519: error while processing file '?/rdbms/admin/doptim.bsq' near line 15 ORA-00604: error occurred at recursive SQL level 1 ORA-01658: unable to create INITIAL extent for segment in tablespace SYSTEM Process ID: 4562 Session ID: 1 Serial number: 3 格式的if-queries解决它吗?

try except

1 个答案:

答案 0 :(得分:0)

您有一个变量response,根据其值,您必须打印出highoklow

#!/usr/bin/python
import requests

reptime = 0.5

url="http://www.google.com"

def time(desired_resp):
    try:
        response = requests.get(url,timeout=desired_resp).elapsed.total_seconds()
    except requests.exceptions.Timeout as f:
        response = desired_resp
    if response < desired_resp*0.5:
        print "Low reponse time"
    elif response < desired_resp:
        print "Ok reponse time"
    else:
        print "High response time"
    print response

time(reptime)