-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[BUG] RecursionError when attempting to capture a traceback from an error (Rich v14.0.0) #3682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I will need an MRE from you, if you would like me to look in to this. |
Okay, will do! It appears to have something to do with Python 3.11's |
I've reproduced this is a very specific context, which I'm having trouble isolating the cause of. The key symptom involves the continue block at Lines 575 to 580 in 8c4d3d1
When the bug this occurs, Apologies I can't provide a minimal example yet - I've tried for hours to reproduce this in isolation without success. However, it consistently reproduces in our production stack, which uses Summary: the stop condition in |
EDIT: stripped a few more lines out, verified it also occurs with using asyncio taskgroups directly. This is all spawning from "unhandled error in taskgroup" so it's likely specific to how taskgroups form ExceptionGroups Update - managed to strip it down to a shareable example, it's still dependent on several external dependencies, so I'm going to see if I can capture it a bit better elsewhere. Dependencies:
import anyio
import logging.config
import uvicorn
import fastapi
from starlette.middleware.base import BaseHTTPMiddleware
logger = logging.getLogger(__name__)
app = fastapi.FastAPI()
@app.get("/api/v1/foo")
async def root():
raise Exception("original exception")
async def run():
async with anyio.create_task_group() as tg:
app.add_middleware(BaseHTTPMiddleware)
server = uvicorn.Server(uvicorn.Config(app, host="0.0.0.0", port=12345, log_config=None, log_level=None))
tg.start_soon(server.serve)
def main():
anyio.run(run, backend="asyncio")
if __name__ == "__main__":
# Configure logging with RichHandler
logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "rich.logging.RichHandler",
"level": "INFO",
"rich_tracebacks": True,
}
},
"root": {"handlers": ["console"], "level": "INFO"},
"incremental": False,
})
main() Then, reach the API with curl (you can use httpx and call it from within the task group but I didn't want to add more confusion)
Running this will cause the issue - it'll log
before it hangs for a moment and then another error about maximum recursion depth blows up the console. The middleware is necessary, removing it causes it to just log an error as normal. If using a debugger, placing it in |
For convenience, here's a version that calls the api for you and therefore requires no further input to trigger the error import anyio
import logging.config
import uvicorn
import fastapi
import httpx
from starlette.middleware.base import BaseHTTPMiddleware
logger = logging.getLogger(__name__)
app = fastapi.FastAPI()
@app.get("/api/v1/foo")
async def root():
raise Exception("original exception")
async def call_api():
await anyio.sleep(2) # wait for the server to start
async with httpx.AsyncClient() as client:
await client.get("http://localhost:12345/api/v1/foo")
async def run():
async with anyio.create_task_group() as tg:
app.add_middleware(BaseHTTPMiddleware)
server = uvicorn.Server(uvicorn.Config(app, host="0.0.0.0", port=12345, log_config=None, log_level=None))
tg.start_soon(server.serve)
tg.start_soon(call_api)
def main():
anyio.run(run, backend="asyncio")
if __name__ == "__main__":
# Configure logging with RichHandler
logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "rich.logging.RichHandler",
"level": "INFO",
"rich_tracebacks": True,
}
},
"root": {"handlers": ["console"], "level": "INFO"},
"incremental": False,
})
main() |
Describe the bug
After updating to Rich v14.0.0 I get a
RecursionError
when attempting to capture a traceback from an error.Here's my function along with the helper function to create the traceback:
Here's the stack trace for the
RecursionError
:Platform
What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
Running on Linux, running in the VS Code integrated terminal
I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.
If you're using Rich in a terminal:
The text was updated successfully, but these errors were encountered: