Skip to content

Commit

Permalink
Added __traceback_hide__ to skip frames in tracebacks (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigfootjon committed Mar 31, 2023
1 parent 0357158 commit be6635e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions asgiref/current_thread_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, future, fn, args, kwargs):
self.kwargs = kwargs

def run(self):
__traceback_hide__ = True # noqa: F841
if not self.future.set_running_or_notify_cancel():
return
try:
Expand Down
9 changes: 9 additions & 0 deletions asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def __init__(self, awaitable, force_new_loop=False):
self.main_event_loop = None

def __call__(self, *args, **kwargs):
__traceback_hide__ = True # noqa: F841

# You can't call AsyncToSync from a thread with a running event loop
try:
event_loop = asyncio.get_running_loop()
Expand Down Expand Up @@ -289,6 +291,9 @@ async def main_wrap(
Wraps the awaitable with something that puts the result into the
result/exception future.
"""

__traceback_hide__ = True # noqa: F841

if context is not None:
_restore_context(context[0])

Expand Down Expand Up @@ -388,6 +393,7 @@ def __init__(
pass

async def __call__(self, *args, **kwargs):
__traceback_hide__ = True # noqa: F841
loop = asyncio.get_running_loop()

# Work out what thread to run the code in
Expand Down Expand Up @@ -461,6 +467,9 @@ def thread_handler(self, loop, source_task, exc_info, func, *args, **kwargs):
"""
Wraps the sync application with exception handling.
"""

__traceback_hide__ = True # noqa: F841

# Set the threadlocal for AsyncToSync
self.threadlocal.main_event_loop = loop
self.threadlocal.main_event_loop_pid = os.getpid()
Expand Down

0 comments on commit be6635e

Please sign in to comment.