Skip to content

New REPL sometimes incrementally indents traceback lines #131968

@picnixz

Description

@picnixz

Bug report

Bug description:

The reproducer I found comes from #84376 and it was entirely by chance that I stumbled upon the REPL issue itself. I don't know if it's because we're using multiprocessing or if it's because the exception is in another thread or process, or if it's again something else.

Python 3.14.0a6+ (heads/main:3b3720f1a26, Apr  1 2025, 10:14:27) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
... q = multiprocessing.Queue()
... try:
...     q.put(lambda: None)
...     print("Success!")
... except Exception:
...     print("Failure")
...
Success!
>>> AttributeError: module '__main__' has no attribute '<lambda>'

                                                                 During handling of the above exception, another exception occurred:

                                                                                                                                    Traceback (most recent call last):
                                                                                                                                                                        File "/$HOME/lib/python/cpython/Lib/multiprocessing/queues.py", line 262, in _feed
                                                                                           obj = _ForkingPickler.dumps(obj)
                                                                                                                             File "/$HOME/lib/python/cpython/Lib/multiprocessing/reduction.py", line 51, in dumps
                                                  cls(buf, protocol).dump(obj)
                                                                                  ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
                                                                                                              _pickle.PicklingError: Can't pickle <function <lambda> at 0x7f1410a13a10>: it's not found as __main__.<lambda>

KeyboardInterrupt
>>>

In the old REPL, the traceback is properly shown.

Python 3.14.0a6+ (heads/main:3b3720f1a26, Apr  1 2025, 10:14:27) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> q = multiprocessing.Queue()
>>> try:
...     q.put(lambda: None)
...     print("Success!")
... except Exception:
...     print("Failure")
...
Success!
>>> AttributeError: module '__main__' has no attribute '<lambda>'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/$HOME/lib/python/cpython/Lib/multiprocessing/queues.py", line 262, in _feed
    obj = _ForkingPickler.dumps(obj)
  File "/$HOME/lib/python/cpython/Lib/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
_pickle.PicklingError: Can't pickle <function <lambda> at 0x7f2119283350>: it's not found as __main__.<lambda>

>>>

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions