Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adafruit/Adafruit_CircuitPython_asyncio
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: db3b03c4c68a4d4d32a3d145f6fad8935a89a345
Choose a base ref
...
head repository: adafruit/Adafruit_CircuitPython_asyncio
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7469b5fd5e24b856f01d59a03eed1c8e7049f0d9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Nov 14, 2023

  1. chore: make traceback module optional

    some boards don't provide traceback so we can add a minimal implementation
    that works _good enough_ in those cases so asyncio can still be used
    imnotjames committed Nov 14, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    imnotjames James Ward
    Copy the full SHA
    8d69d54 View commit details

Commits on Jan 1, 2024

  1. Merge pull request #59 from imnotjames/chore/optional-traceback

    chore: make traceback module optional
    FoamyGuy authored Jan 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7469b5f View commit details
Showing with 64 additions and 2 deletions.
  1. +7 −2 asyncio/core.py
  2. +57 −0 asyncio/traceback.py
9 changes: 7 additions & 2 deletions asyncio/core.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,12 @@
"""

from adafruit_ticks import ticks_ms as ticks, ticks_diff, ticks_add
import sys, select, traceback
import sys, select

try:
from traceback import print_exception
except:
from .traceback import print_exception

# Import TaskQueue and Task, preferring built-in C code over Python code
try:
@@ -380,7 +385,7 @@ def default_exception_handler(loop, context):
"""The default exception handler that is called."""

exc = context["exception"]
traceback.print_exception(None, exc, exc.__traceback__)
print_exception(None, exc, exc.__traceback__)

def call_exception_handler(context):
"""Call the current exception handler. The argument *context* is passed through
57 changes: 57 additions & 0 deletions asyncio/traceback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: 2019-2020 Damien P. George
#
# SPDX-License-Identifier: MIT
#
# MicroPython uasyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George
"""
Fallback traceback module if the system traceback is missing.
"""

try:
from typing import List
except ImportError:
pass

import sys


def _print_traceback(traceback, limit=None, file=sys.stderr) -> List[str]:
if limit is None:
if hasattr(sys, "tracebacklimit"):
limit = sys.tracebacklimit

n = 0
while traceback is not None:
frame = traceback.tb_frame
line_number = traceback.tb_lineno
frame_code = frame.f_code
filename = frame_code.co_filename
name = frame_code.co_name
print(' File "%s", line %d, in %s' % (filename, line_number, name), file=file)
traceback = traceback.tb_next
n = n + 1
if limit is not None and n >= limit:
break


def print_exception(exception, value=None, traceback=None, limit=None, file=sys.stderr):
"""
Print exception information and stack trace to file.
"""
if traceback:
print("Traceback (most recent call last):", file=file)
_print_traceback(traceback, limit=limit, file=file)

if isinstance(exception, BaseException):
exception_type = type(exception).__name__
elif hasattr(exception, "__name__"):
exception_type = exception.__name__
else:
exception_type = type(value).__name__

valuestr = str(value)
if value is None or not valuestr:
print(exception_type, file=file)
else:
print("%s: %s" % (str(exception_type), valuestr), file=file)