diff --git a/doc/starting.rst b/doc/starting.rst index c55edeb9..5f24f815 100644 --- a/doc/starting.rst +++ b/doc/starting.rst @@ -87,8 +87,7 @@ the terminal size: #. ``PUDB_TERM_SIZE`` environment variable #. Size of the terminal in which the debugged program is running (as returned by ``os.get_terminal_size()``) -#. Default fallback value of ``(80, 20)`` if one of the previous steps - fails with an exception +#. Default fallback value of ``(80, 20)`` At this point, the debugger will look for a free port and wait for a telnet connection:: diff --git a/pudb/forked.py b/pudb/forked.py index 66ae091c..d8ac88ad 100644 --- a/pudb/forked.py +++ b/pudb/forked.py @@ -14,15 +14,18 @@ def set_trace(paused=True, frame=None, term_size=None): if frame is None: frame = sys._getframe().f_back if term_size is None: - try: - term_size = os.environ.get("PUDB_TERM_SIZE", "") + term_size = os.environ.get("PUDB_TERM_SIZE") + if term_size is not None: term_size = tuple(map(int, term_size.split("x"))) if len(term_size) != 2: + raise ValueError("PUDB_TERM_SIZE should have two dimensions") + else: + try: # Getting terminal size s = os.get_terminal_size() term_size = (s.columns, s.lines) - except Exception: - term_size = (80, 24) + except Exception: + term_size = (80, 24) Debugger( stdin=open("/dev/stdin"), diff --git a/pudb/remote.py b/pudb/remote.py index ee6adea4..373424cb 100644 --- a/pudb/remote.py +++ b/pudb/remote.py @@ -45,15 +45,13 @@ from pudb.debugger import Debugger -__all__ = ["PUDB_RDB_HOST", "PUDB_RDB_PORT", "PUDB_TERM_SIZE", - "default_port", "debugger", "set_trace", +__all__ = ["PUDB_RDB_HOST", "PUDB_RDB_PORT", "default_port", "debugger", "set_trace", "debug_remote_on_single_rank"] default_port = 6899 PUDB_RDB_HOST = os.environ.get("PUDB_RDB_HOST") or "127.0.0.1" PUDB_RDB_PORT = int(os.environ.get("PUDB_RDB_PORT") or default_port) -PUDB_TERM_SIZE = os.environ.get("PUDB_TERM_SIZE", "") #: Holds the currently active debugger. _current = [None] @@ -140,13 +138,17 @@ def __init__( self.out = out if term_size is None: - try: - term_size = tuple(map(int, PUDB_TERM_SIZE.split("x"))) + term_size = os.environ.get("PUDB_TERM_SIZE") + if term_size is not None: + term_size = tuple(map(int, term_size.split("x"))) if len(term_size) != 2: + raise ValueError("PUDB_TERM_SIZE should have two dimensions") + else: + try: s = os.get_terminal_size() term_size = (s.columns, s.lines) - except Exception: - term_size = (80, 24) + except Exception: + term_size = (80, 24) self._prev_handles = sys.stdin, sys.stdout self._client, (address, port) = self.get_client(