This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pickling recursion error, did not import pickle
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.10, Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Octopi, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2021-06-10 15:31 by Octopi, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg395542 - (view) Author: Violet Godfrey (Octopi) Date: 2021-06-10 15:31
I accidentally created an infinite recursion. The error referenced pickling but I did not import pickle. 

To reproduce: 
def permute(inputList):
    '''permute(inputList) -> list
    returns list of all permutations of inputList
    CURRENTLY DOESN'T ACTUALLLY WORK PROPERLY'''
    for i in range(len(inputList)-1):
        tempList = inputList[:-i-2]
        tempList.append(inputList[-1])
        for num in inputList[-i-2:-1]:
            tempList.append(num)
        print(tempList)
        permute(tempList)  # runs infinitely (whoops)
    print()

permute([1,2,3,4])

Error thrown: 
Traceback (most recent call last):
  File "C:\Users\Violet\Documents\Python Files\test.py", line 14, in <module>
    permute([1,2,3,4])
  File "C:\Users\Violet\Documents\Python Files\test.py", line 11, in permute
    permute(tempList)  # runs infinitely (whoops)
  File "C:\Users\Violet\Documents\Python Files\test.py", line 11, in permute
    permute(tempList)  # runs infinitely (whoops)
  File "C:\Users\Violet\Documents\Python Files\test.py", line 11, in permute
    permute(tempList)  # runs infinitely (whoops)
  [Previous line repeated 1009 more times]
  File "C:\Users\Violet\Documents\Python Files\test.py", line 10, in permute
    print(tempList)
RecursionError: maximum recursion depth exceeded while pickling an object
msg395552 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-06-10 16:34
It is because you run the code in IDLE.

print(tempList) converts argument to string and write it to sys.stdout. In IDLE sys.stdout is a proxy object which uses RPC to communicate with the IDLE process which should insert the written text in the console text widget. Pickle is used for encoding command and arguments. Here you get a recursion error in pickle because when print(tempList) is executed the recursion depth almost reached the limit.
msg395587 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-10 23:11
The 'while pickling' part of the message is specific to running in IDLE, as Serhiy explained, but the recursion error itself is due to writing a program with infinite recursion.  The program switches the last two items back and forth indefinitely.  When run directly in Python, it gives the same error, with a different 'while' part.

Violet, this tracker is for patching Python docs and the CPython interpreter.  Please ask questions about program behavior elsewhere, such as python-list.
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88545
2021-06-10 23:11:29terry.reedysetstatus: open -> closed
versions: + Python 3.10
messages: + msg395587

assignee: terry.reedy ->
resolution: not a bug
stage: resolved
2021-06-10 16:34:52serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg395552
2021-06-10 15:31:07Octopicreate