You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
“I/O operation on closed file” when try with "Debugging from a separate terminal" #598
$ cat try.py
from datetime import datetime
import os
import sys
from pudb.remote import set_trace
set_trace()
if __name__ == "__main__":
print(' '.join(sys.argv))
begin = datetime.now()
print("begin process", os.getpid(), "at", begin.strftime('%Y-%m-%d %H:%M:%S'))
On the first terminal, I tried with:
$ tty
/dev/pts/3
$ perl -MPOSIX -e pause
On the second terminal, I met the below issue. Should I run with 'root'? thanks.
$ PUDB_TTY=/dev/pts/3 pudb try.py
Traceback (most recent call last):
File "/home/testit/miniconda3/envs/trypudb/lib/python3.9/site-packages/pudb/debugger.py", line 2434, in call_with_ui
return f(*args, **kwargs)
File "/home/testit/miniconda3/envs/trypudb/lib/python3.9/site-packages/pudb/debugger.py", line 2740, in interaction
self.event_loop()
File "/home/testit/miniconda3/envs/trypudb/lib/python3.9/site-packages/pudb/debugger.py", line 2696, in event_loop
self.screen.draw_screen(self.size, canvas)
File "/home/testit/miniconda3/envs/trypudb/lib/python3.9/site-packages/urwid/raw_display.py", line 708, in draw_screen
self._setup_G1()
File "/home/testit/miniconda3/envs/trypudb/lib/python3.9/site-packages/urwid/raw_display.py", line 687, in _setup_G1
self.write(escape.DESIGNATE_G1_SPECIAL)
File "/home/testit/miniconda3/envs/trypudb/lib/python3.9/site-packages/urwid/raw_display.py", line 286, in write
self._term_output_file.write(data)
ValueError: I/O operation on closed file.
Reacted by Taylor Cochran, Stavros Ntentos, Marc Herbert, Matt Duck and Matt Rixman
I believe I’ve found an alternative way to achieve the PUDB_TTY trick, instead of setting the end var, if you redirect stein to be the tty, it seems to work:
if you also pipe the output into that tty, you end up with the UI being drawn in the first terminal, and being able to interact with it there.
Sadly this doesn’t solve the issue I have that when the app prints anything, the tui disappears completely in the second shell, and doesn’t reappear until the app exits. sending Ctrl-l via the first terminal doesn’t seem to redraw. Surely I’m not the first person to ever debug an app that logs to stdout?
Looks like the issue above isn’t related to to printing to stdout (they were just correlated in time), something strange seems to be happening with tkinter which causes the tui to disappear completely sometime before the main window appears.
Traceback (most recent call last):
File ".venv/lib/python3.11/site-packages/pudb/debugger.py", line 466, in user_line
self.interaction(frame)
File ".venv/lib/python3.11/site-packages/pudb/debugger.py", line 436, in interaction
self.ui.call_with_ui(self.ui.interaction, exc_tuple,
File ".venv/lib/python3.11/site-packages/pudb/debugger.py", line 2540, in call_with_ui
self.show()
File ".venv/lib/python3.11/site-packages/pudb/debugger.py", line 2531, in show
self.screen.start()
File ".venv/lib/python3.11/site-packages/urwid/display_common.py", line 813, in start
self._start(*args, **kwargs)
File ".venv/lib/python3.11/site-packages/urwid/raw_display.py", line 222, in _start
self.write(escape.SWITCH_TO_ALTERNATE_BUFFER)
File ".venv/lib/python3.11/site-packages/urwid/raw_display.py", line 286, in write
self._term_output_file.write(data)
ValueError: I/O operation on closed file.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".venv/lib/python3.11/site-packages/pudb/debugger.py", line 2456, in show_internal_exc_dlg
self._show_internal_exc_dlg(exc_tuple)
File ".venv/lib/python3.11/site-packages/pudb/debugger.py", line 2479, in _show_internal_exc_dlg
urwid=".".join(map(str, urwid.version.version)),
^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'urwid.version' has no attribute 'version'
I successfully git bisected this. Reverting one-line commit 277980e (July 2022) avoids this issue. That tty.close() really does look like a smoking gun!
Revert successfully tested on top of current version 8c8f9d4.
I don't know yet if this revert has any undesired side-effect; I only found this right now and wanted to share this "breakthrough" ASAP. That commit message and the corresponding PR #534 were both empty. I will for sure use that one-line revert "in anger" and report back if I find any problem.
I will for sure use that one-line revert "in anger" and report back if I find any problem.
This revert did not last long. It makes PUDB_TTY go further but things are still not OK: many keys don't work and the terminal acts strangely. Even without a commit message I guess this line was there for a reason.
Activity
axman6 commentedon Jun 1, 2023
I’m also having this issue, which is problematic because when the app I’m debugging prints anything, the pudb UI disappears until I terminate the app.
axman6 commentedon Jun 1, 2023
I believe I’ve found an alternative way to achieve the PUDB_TTY trick, instead of setting the end var, if you redirect stein to be the tty, it seems to work:
if you also pipe the output into that tty, you end up with the UI being drawn in the first terminal, and being able to interact with it there.
Sadly this doesn’t solve the issue I have that when the app prints anything, the tui disappears completely in the second shell, and doesn’t reappear until the app exits. sending Ctrl-l via the first terminal doesn’t seem to redraw. Surely I’m not the first person to ever debug an app that logs to stdout?Looks like the issue above isn’t related to to printing to stdout (they were just correlated in time), something strange seems to be happening with tkinter which causes the tui to disappear completely sometime before the main window appears.
stdedos commentedon Oct 9, 2023
The latest version
also gives me
😕
stdedos commentedon Oct 9, 2023
Also seems to be related to #317 (comment)?
marc-h38 commentedon Dec 4, 2023
I successfully git bisected this. Reverting one-line commit 277980e (July 2022) avoids this issue. That
tty.close()really does look like a smoking gun!Revert successfully tested on top of current version 8c8f9d4.
I don't know yet if this revert has any undesired side-effect; I only found this right now and wanted to share this "breakthrough" ASAP. That commit message and the corresponding PR #534 were both empty. I will for sure use that one-line revert "in anger" and report back if I find any problem.
stdedos commentedon Dec 4, 2023
That's awesome work!
Can you contribute your testing methodology? 🙏
marc-h38 commentedon Dec 4, 2023
Can you confirm it works for you too?
marc-h38 commentedon Dec 4, 2023
This revert did not last long. It makes PUDB_TTY go further but things are still not OK: many keys don't work and the terminal acts strangely. Even without a commit message I guess this line was there for a reason.
Instead I installed the last official release before this commit and so far things seem to work:
pip install pudb==2022.1.2https://pypi.org/project/pudb/#history
ejeffrey commentedon Feb 10, 2024
I'm having this issue too, and for me removing tty_file.close() call fixed the problem entirely.
msbrogli commentedon Feb 15, 2024
I also had the same issues and removing the
tty_file.close()fixed the issue entirely.MatrixManAtYrService commentedon Jul 14, 2024
Same here, so I made a PR.
inducer commentedon Jul 23, 2024
Fixed by #656.