Python中非常长的循环似乎超时了

时间:2014-07-18 18:13:51

标签: python python-2.7 ipython

我遇到了一个奇怪的问题,当在Python中运行极长的循环/计算时,循环似乎终止但没有计算结果。此外,解释器似乎崩溃,不支持进一步的计算。

环境:使用IPython解释器的Python 2.7(Enthought Canopy)。

例如,考虑虚函数:

>>> def myfunc(n):
       t = 0;
       for i in xrange(n):
           t += i
       return t
>>> myfunc(100000000)
Out[7]: 4999999950000000L
>>> myfunc(10e10L)   
##---- runs for a minute with no response / return-value and then the prompt shows.----
>>>
>>> myfunc(100)
---- no response --- 
>>> print 'hello'
---- no response --- 
>>> 

虽然我希望大循环溢出 - 并且可能会抛出错误,但我不确定为什么函数调用会返回而没有任何结果。这种行为有望吗?

0 个答案:

没有答案