Title: Pickling recursion error, did not import pickle
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.10, Python 3.8
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 2021-06-10 23:11 by terry.reedy. 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
    for i in range(len(inputList)-1):
        tempList = inputList[:-i-2]
        for num in inputList[-i-2:-1]:
        permute(tempList)  # runs infinitely (whoops)


Error thrown: 
Traceback (most recent call last):
  File "C:\Users\Violet\Documents\Python Files\", line 14, in <module>
  File "C:\Users\Violet\Documents\Python Files\", line 11, in permute
    permute(tempList)  # runs infinitely (whoops)
  File "C:\Users\Violet\Documents\Python Files\", line 11, in permute
    permute(tempList)  # runs infinitely (whoops)
  File "C:\Users\Violet\Documents\Python Files\", line 11, in permute
    permute(tempList)  # runs infinitely (whoops)
  [Previous line repeated 1009 more times]
  File "C:\Users\Violet\Documents\Python Files\", line 10, in permute
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.
Date User Action Args
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