函数range()的步长值如何变化?

时间:2019-08-08 11:09:07

标签: python

我在python中具有以下功能。

我的目标是生成从1到函数check_overload()返回除0以外的其他值的iperf流量。然后,我计算overload_point_A。毕竟,我转到#Step。 II,其中以相同的过载点值连续发送流量。

    #######
    # Step. I
    #######
count = 10000
r = range(1, count)
    for bandwidth in r:
        print "============"
        print ("bandwidth = "+str(bandwidth))
        check = check_overload(SegmentPath, Router_1, Router_2, Router_3, Router_4, step, capacity)
        for overload_point_A in check:
            if overload_point_A == 0:
                print (color.RED + "functionA: iperf " + str(bandwidth)+""+color.END)
                break    
            else:
                print "Overload Point I. = ", overload_point_A
                del r[bandwidth:]
                time.sleep(sleepTime)
                break

    #######
    # Step. II
    #######
    print("Overloaded of Tunnel 4 at " + str(overload_point_A) + " kbps.")
    isrunninga = 0
    bandwidth = overload_point_A
    while True:
        print("Continuous Phase I. bandwidth = "+ str(bandwidth)+" Mbps")
        time.sleep(sleepTime)
        if isrunninga == 1 :
            bandwidth = bandwidth + 1

我面临的问题是,当我修改r = range(1, count)并添加一个整数range()步长值r = range(1, count, step)时,该函数仅运行Step,有什么方法可以修复它吗? / p>

这是我不带range()功能的输出:

...
..
======
bandwidth = 7
Link is not overloaded
load =  12.0  <  20 - 2 *  3  =  14
functionA: iperf 7
============
bandwidth = 8
Link is not overloaded
load =  12.0  <  20 - 2 *  3  =  14
functionA: iperf 8
============
bandwidth = 9
Link is overloaded
Overload Point I. =  14.0
Overloaded of Tunnel 4 at 14.0 kbps.
Continuous Phase I. bandwidth = 14.0 Mbps

这是我为range()函数设置step = 3的结果:

...
..
bandwidth = 13
Link is not overloaded
load =  4.0  <  20 - 2 *  3  =  14
functionA: iperf 13
============
bandwidth = 16
Link is not overloaded
load =  11.0  <  20 - 2 *  3  =  14
functionA: iperf 16
============
bandwidth = 19
Link is not overloaded
load =  11.0  <  20 - 2 *  3  =  14
functionA: iperf 19
============
bandwidth = 22
Link is not overloaded
load =  11.0  <  20 - 2 *  3  =  14
functionA: iperf 22
============
bandwidth = 25
Link is overloaded
Overload Point I. =  13.0
============
bandwidth = 28
Link is overloaded
Overload Point I. =  13.0
...

0 个答案:

没有答案