Python time.sleep()运行到浮点异常

时间:2012-06-01 22:45:01

标签: python floating-point-exceptions

我在GNURadio程序中使用Python time.sleep()函数。但是,尽管我提供了一个浮点参数,但代码会遇到意外的浮点异常。请在下面找到相关的代码片段(请忽略调试“Hehe”: - )):

while not ack and timeout < 5: #FIXME: Hard-coded timeout interval
    print "Hehe5"   
    timeout+=1
    print "Hehe6"
    time.sleep(0.5)
    print "Hehe7"
    with lock:
        ack=recvd_prev_ack
    print "Hehe8"

这给出了以下输出:

Sent pktno=   0
Hehe
Hehe1
Hehe2
Hehe3
Hehe4
Hehe5
Hehe6
Floating point exception

所以错误点确实是time.sleep()。有人可以解释一下这里会发生什么吗?我的Python版本是2.7.1。

谢谢和问候, Dhrubo

1 个答案:

答案 0 :(得分:3)

这里发生的事情是你的程序是线程化的,并且浮点异常发生在另一个线程中(不是你认为的地方)。