◐ Shell
clean mode source ↗

Message 158326 - Python tracker

The "RuntimeError: maximum recursion depth exceeded" message is normally only triggered by pure Python recursion, so I would not have expected it here, but there should be some sort of graceful MemoryError or somesuch rather than a segfault.

The following code narrows it down to some issue in starmap():

    def gstarmap(func, iterable):
        for tup in iterable:
            yield func(*tup)

    def mylist(iterable):
        return [x for x in iterable]

    a = b = [1]
    for i in xrange(100000):

        # Things that trigger a segfault:                                              
        #a = starmap(add, izip(a, b))                                                
        #a = starmap(add, iter( (a, b)  ))                                           
        a = starmap(add, (a, b)  )

        # Things that exit cleanly with a RuntimeError                               
        #a = gstarmap(add, iter( (a, b)  ))                                          
        #a = (x+y   for x, y in iter( (a, b)  ))     

    mylist(a)

One possibility may be that starmap.next needs to clear StopIteration exceptions in the same way as PyIter_Next():

    if (result == NULL &&
        PyErr_Occurred() &&
        PyErr_ExceptionMatches(PyExc_StopIteration))
        PyErr_Clear();