Created
February 21, 2018 13:54
-
-
Save smurfix/65d7488aaab838f5b173af7cde7a3a9e to your computer and use it in GitHub Desktop.
Single-step through trio without falling asleep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Lib/pdb.py 2018-02-15 14:49:47.668435454 +0100 | |
+++ ../pdb.py 2018-02-21 14:48:21.039713323 +0100 | |
@@ -246,6 +246,10 @@ | |
that we ever need to stop in this function.""" | |
if self._wait_for_mainpyfile: | |
return | |
+ if self.force_step(frame): | |
+ self.onecmd("step") | |
+ self.forget() | |
+ return | |
if self.stop_here(frame): | |
self.message('--Call--') | |
self.interaction(frame, None) | |
@@ -257,7 +261,10 @@ | |
or frame.f_lineno <= 0): | |
return | |
self._wait_for_mainpyfile = False | |
- if self.bp_commands(frame): | |
+ if self.force_step(frame): | |
+ self.onecmd("step") | |
+ self.forget() | |
+ elif self.bp_commands(frame): | |
self.interaction(frame, None) | |
def bp_commands(self, frame): | |
@@ -288,15 +295,39 @@ | |
"""This function is called when a return trap is set here.""" | |
if self._wait_for_mainpyfile: | |
return | |
+ if self.force_step(frame): | |
+ self.onecmd("step") | |
+ self.forget() | |
+ return | |
frame.f_locals['__return__'] = return_value | |
self.message('--Return--') | |
self.interaction(frame, None) | |
+ def force_step(self, frame): | |
+ if "/trio/" in frame.f_code.co_filename: | |
+ return True | |
+ if "/pytest_trio/" in frame.f_code.co_filename: | |
+ return True | |
+ if "/async_generator/" in frame.f_code.co_filename: | |
+ return True | |
+ if "/sortedcontainers/" in frame.f_code.co_filename: | |
+ return True | |
+ if frame.f_code.co_filename.startswith("<attrs generated "): | |
+ return True | |
+ if frame.f_code.co_filename.endswith("/contextlib.py"): | |
+ return True | |
+ if frame.f_code.co_name == "getcoroutinestate": | |
+ return True | |
+ | |
def user_exception(self, frame, exc_info): | |
"""This function is called if an exception occurs, | |
but only if we are to stop at or just below this level.""" | |
if self._wait_for_mainpyfile: | |
return | |
+ if self.force_step(frame): | |
+ self.onecmd("step") | |
+ self.forget() | |
+ return | |
exc_type, exc_value, exc_traceback = exc_info | |
frame.f_locals['__exception__'] = exc_type, exc_value | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment