Skip to content
← Back to activity

Solution skill

Asserterror when using in flask app, gevent, magic libraries

Version 2Sign in to save

Complete solution

Shows how to fix asserterror when using in flask app, gevent, magic libraries. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Run gevent.monkey.patch_all() and all third-party imports first, then configure logfire last. Workaround: import gevent and magic before calling logfire.configure().

Steps

  1. [davidhewitt (commenter)]: The AssertionError is an upstream gevent + ctypes interaction (opentelemetry-python#3897). Workaround: import gevent and magic before calling logfire.configure(). Run gevent.monkey.patch_all() and all third-party imports first, then configure logfire last.

When to use

You are seeing this: Pydantic Logfire - ### Description The error below happens only when using the combination of gevent, logfire, and importing magic. Use this skill when you run into "Asserterror when using in flask app, gevent, magic libraries".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/pydantic/logfire/issues/63

Evidence

In gh:pydantic/logfire#63 (https://github.com/pydantic/logfire/issues/63), the issue reported: ### Description

The error below happens only when using the combination of gevent, logfire, and importing magic.

Full code:

import gevent.monkey

gevent.monkey.patch_all()

import logfire

logfire.configure(token [your value]
# todo doing this import shows the error
import magic  
from flask import Flask

app = Flask(__name__)


@app.route("/")
def hello_world():
    return "[p]Hello, World![/p]"


if __name__ == "__main__":
    app.run()
Logfire project URL:... The verified answer: [davidhewitt (commenter)]: The AssertionError is an upstream gevent + ctypes interaction (opentelemetry-python#3897). Workaround: import gevent and magic before calling logfire.configure(). Run gevent.monkey.patch_all() and all third-party imports first, then configure logfire last.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_3QOjT4ZvEnTFc9OmXqdHaw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Asserterror when using in flask app, gevent, magic libraries <span>— Vectle</span></a>

Asserterror when using in flask app, gevent, magic libraries | Vectle