Comments (8)
What is sys.stdout/stdin when you run that?
from pudb.
So I've added to the file pudb/debugger.py
, line 1187:
if curses:
print sys.stdout
print sys.stderr
curses.setupterm()
... which prints out:
<nose.plugins.xunit.Tee object at 0x1fa4cd0>
<nose.plugins.xunit.Tee object at 0x1fa4d10>
This happens when using pudb
called from nosetests
. I believe this used to work before I recently re-installed my system.
from pudb.
Can you try current git? If it works, I'll push out a new version.
from pudb.
Yup, I just tested it and it works like a charm! Thanks @inducer!
from pudb.
2013.3.4 released.
from pudb.
@inducer I am encountering this problem when trying to pudb.set_trace() in a unittest-based test runner process. I suspect the problem is caused by the framework or my code changing stdout/err in an unexpected way, but have not been able to determine root cause and could use your help.
I am using python 2.7.13 on debian 9.3, and using the following relevant packages:
Name: pudb
Version: 2018.1
Name: Pygments
Version: 2.2.0
Name: urwid
Version: 2.0.1
When I put pudb.set_trace in one of my tests and run, I see this stack trace:
.
.
. (entry point from my code)
File "/usr/lib/python2.7/bdb.py", line 49, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 187, in dispatch_line
self.user_line(frame)
File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 408, in user_line
self.interaction(frame)
File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 376, in interaction
show_exc_dialog=show_exc_dialog)
File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2118, in call_with_ui
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2362, in interaction
self.event_loop()
File "/usr/local/lib/python2.7/dist-packages/pudb/debugger.py", line 2315, in event_loop
self.size = self.screen.get_cols_rows()
File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 655, in get_cols_rows
termios.TIOCGWINSZ, ' '*4)
TypeError: argument must be an int, or have a fileno() method.
The main process above is setting sys.stdout and sys.stderr to custom "Tee" objects that "fans out" these streams to a file in addition to the original streams. This tee object indeed implements fileno() so I'm not sure what it's complaining about:
class Tee(object):
'''Implements functionality similar to tee program on linux.
At construction, overwrites sys.stdout (or sys.stderr) with itself, and opens file.
Subsequently, When sys.stdout (or sys.stderr) is written to by this process, the string
is written to both the original sys.stdout (or sys.stderr) and the specified file.
At destruction, the original sys.stdout (or sys.stderr) is restored and the file closed.
The default file mode 'a' enables the same file to be written to multiple
times within the same process, by creating and destroying Tee objects
with the same filename. It is also required mode when using 2 Tee objects pointing
at the same file (e.g. one for stdout and one for stderr).
'''
def __init__(self, filename, what_to_redirect=sys.stdout, mode='a'):
self.file = open(filename, mode)
self.what_to_redirect = what_to_redirect
if self.what_to_redirect is sys.stdout:
sys.stdout = self
elif self.what_to_redirect is sys.stderr:
sys.stderr = self
def __del__(self):
if self.what_to_redirect is sys.stdout:
sys.stdout = self.what_to_redirect
elif self.what_to_redirect is sys.stderr:
sys.stderr = self.what_to_redirect
self.flush()
self.file.close()
def write(self, data):
self.file.write(data)
self.what_to_redirect.write(data)
def flush(self):
self.file.flush()
def fileno(self):
'''Pudb was barfing when hitting a breakpoint bc this method wasn't defined.
I believe the right thing to do is to return the file descriptor of what is
being redirected, i.e. stderr/out.'''
self.what_to_redirect.fileno()
When I insert:
print sys.stdout
print sys.stderr
in either the pudb/debugger.py or the urwid/raw_display.py lines, I get a mysterious syntax error.
I have confirmed pudb.set_trace():
- works in a simple script in same environment
- does not work in some other scripts of mine that run outside/independent of unittest, but only in cases where the set_trace() call is made in another process.
Any clues on how to fix the unittest/Tee case above? Thanks!
from pudb.
@timblaktu That sounds like an issue with urwid/termios not accepting an object it claims to accept. Could you raise an issue there?
from pudb.
Done. urwid/urwid#316 (comment)
Thanks, @inducer.
from pudb.
Related Issues (20)
- "Falling back to custom shell" message printed in internal shell console HOT 2
- default urwid bright-is-bold false HOT 1
- Adding a Watch expression using AutoKey (documentation suggestion) HOT 1
- remote debugging - Cannot disable application log message from garbling up the PuDB UI screen HOT 3
- Pudb UI Exception Encountered: Object 'A' appears to be a sequence, but does not behave like one: iteration over a 0-d tensor HOT 1
- Disable "view output" in remote debug HOT 1
- βI/O operation on closed fileβ when try with "Debugging from a separate terminal" HOT 11
- Error reported when exiting iPython and returning to UI on Mac OS X HOT 3
- Please make this marvel run well on a-Shell app for iPad HOT 1
- "Debugger instance already exists" when used in pytest HOT 5
- Greyscale Theme HOT 4
- New Release HOT 1
- Unable to use `--pdb --pdbcls=pudb.debugger:Debugger` with latest versions of urwid HOT 2
- telnetlib (used for remote debugger) is deprecated in Python 3.12 HOT 4
- Run to line in the same frame HOT 1
- Allow setting term size via env var HOT 1
- PUDB freezes at welcome screen HOT 2
- export PUDB_TTY=... not working
- how can i see or get the current debugged file path?
- Ipython StartUp Script for pudb python shell. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pudb.