Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New REPL sometimes incrementally indents traceback lines #131968

Open
picnixz opened this issue Apr 1, 2025 · 7 comments
Open

New REPL sometimes incrementally indents traceback lines #131968

picnixz opened this issue Apr 1, 2025 · 7 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@picnixz
Copy link
Member

picnixz commented Apr 1, 2025

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

@picnixz picnixz added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error labels Apr 1, 2025
@Viicos
Copy link
Contributor

Viicos commented Apr 1, 2025

I'm wondering if this relates to #129614, where I noticed the same indentation of some traceback.

@sergey-miryanov
Copy link
Contributor

It works fine on Windows 11 x64 with current main:

➜ .\python.bat 
Running Debug|x64 interpreter...
Python 3.14.0a6+ (heads/main-dirty:06822bfbf62, Apr  3 2025, 01:20:23) [MSC v.1943 64 bit (AMD64)] on win32
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 "D:\Sources\_pythonish\cpython\Lib\multiprocessing\queues.py", line 262, in _feed
    obj = _ForkingPickler.dumps(obj)
  File "D:\Sources\_pythonish\cpython\Lib\multiprocessing\reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
    _pickle.PicklingError: Can't pickle <function <lambda> at 0x00000200859BDFD0>: it's not found as __main__.<lambda>

@sergey-miryanov
Copy link
Contributor

Hm, not fine:

➜ .\python.bat
Running Debug|x64 interpreter...
Python 3.14.0a6+ (heads/main:06822bfbf62, Apr  3 2025, 01:25:18) [MSC v.1943 64 bit (AMD64)] on win32
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 "D:\Sources\_pythonish\cpython\Lib\multiprocessing\queues.py", line 262, in _feed
    obj = _ForkingPickler.dumps(obj)
>>>   File "D:\Sources\_pythonish\cpython\Lib\multiprocessing\reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
_pickle.PicklingError: Can't pickle <function <lambda> at 0x000001E63FAE9E50>: it's not found as __main__.<lambda>

@picnixz
Copy link
Member Author

picnixz commented Apr 4, 2025

It might be because of the start method. Linux start method is forkserver while windows is spawn. I'll check that in a few hours. EDIT: didn't matter.

@picnixz
Copy link
Member Author

picnixz commented Apr 4, 2025

@sergey-miryanov

Hm, not fine:

I'm not sure but what do you mean by "not fine"? it looks fine on Windows. It could entirely be a Linux-specific issue btw.

@sergey-miryanov
Copy link
Contributor

@picnixz

Image

@picnixz
Copy link
Member Author

picnixz commented Apr 4, 2025

Oh thank you for pointing out this. I totally missed it!

@picnixz picnixz removed the OS-linux label Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants