Skip to content

Commit

Permalink
✏️ fix clean up stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
MeditationDuck committed Sep 13, 2024
1 parent 928f2d0 commit dcd9346
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions wake/testing/custom_pdb.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import pdb
import sys
from IPython.terminal.debugger import TerminalPdb # Import the correct Pdb class
from IPython.terminal.debugger import TerminalPdb
from typing import Any

class CustomPdb(TerminalPdb):
def __init__(self, prev_stdin, conn, *args, **kwargs):
def __init__(self, program_instance, *args, **kwargs):
"""
Custom Pdb constructor to accept the stdin and connection.
"""
super().__init__(*args, **kwargs) # Initialize the base Pdb class
self.prev_stdin = prev_stdin # Store the original stdin
self.conn = conn # Store the connection for parent communication
self._program_instance = program_instance

def do_continue(self, arg):
"""
Expand All @@ -34,5 +32,5 @@ def cleanup_before_exit(self):
This function performs the cleanup before exiting the debugger.
"""
print("Performing cleanup before exiting the debugger...")
sys.stdin = self.prev_stdin # Restore stdin to its original state
self.conn.send(("breakpoint_handled",))
self._program_instance._setup_stdio()
self._program_instance._conn.send(("breakpoint_handled",))
2 changes: 1 addition & 1 deletion wake/testing/pytest_plugin_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def custom_debugger():
prev = sys.stdin
sys.stdin = os.fdopen(0)
frame = sys._getframe(1)
p = CustomPdb(prev, self._conn)
p = CustomPdb(self)
p.set_trace(frame)
else:
# trace nothing, same as continue
Expand Down

0 comments on commit dcd9346

Please sign in to comment.