GithubHelp home page GithubHelp logo

Comments (8)

inducer avatar inducer commented on July 23, 2024

What is sys.stdout/stdin when you run that?

from pudb.

aconrad avatar aconrad commented on July 23, 2024

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.

inducer avatar inducer commented on July 23, 2024

Can you try current git? If it works, I'll push out a new version.

from pudb.

aconrad avatar aconrad commented on July 23, 2024

Yup, I just tested it and it works like a charm! Thanks @inducer!

from pudb.

inducer avatar inducer commented on July 23, 2024

2013.3.4 released.

from pudb.

timblaktu avatar timblaktu commented on July 23, 2024

@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.

inducer avatar inducer commented on July 23, 2024

@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.

timblaktu avatar timblaktu commented on July 23, 2024

Done. urwid/urwid#316 (comment)

Thanks, @inducer.

from pudb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.