Skip to main content
2 votes
0 answers
174 views

I'm encountering a subtle memory leak in a Python 3.12 application using asyncio, specifically when combining contextvars with deeply nested TaskGroup structures. The issue only appears under high ...
user avatar
4 votes
2 answers
604 views

I am developing a FastAPI app, and my goal is to record some information in a Request scope and then reuse this information later in log records. My idea was to use context vars to store the "...
ow-me's user avatar
  • 313
1 vote
2 answers
204 views

I am learning asyncio callbacks. My task is- I have a message dict, message codes are keys, message texts are values. In coro main I have to create a number of asynchronous tasks (in my case 3 tasks), ...
IzaeDA's user avatar
  • 439
1 vote
2 answers
162 views

Basic process explanation: A process has some initialization parameters that have to be set dynamically at runtime. For example data for a certain amount of dates (final_lookback) have to be pulled ...
shoshanie's user avatar
1 vote
1 answer
205 views

With code below what will happen to SqlAlchemy session that is set in ContextVar if not to reset it? from contextvars import ContextVar from fastapi import FastAPI, BackgroundTasks from sqlalchemy ...
Альберт Александров's user avatar
3 votes
2 answers
2k views

I have this function: async_session = contextvars.ContextVar("async_session") async def get_async_session() -> AsyncGenerator[AsyncSession, None]: async with async_session_maker() as ...
Tom's user avatar
  • 8,171
1 vote
1 answer
195 views

I have a subclass of Thread that I use across my project. In this class, I pass in the ContextVar manually. However, at times (once or twice a day), I notice that the ContextVar in the child thread is ...
Kyuubi's user avatar
  • 1,240
0 votes
2 answers
2k views

Python has the contextvars.copy_context() function which lets you store a copy of the current values of all the ContextVars that are currently active. Then later, you can run with all those values ...
Joseph Garvin's user avatar
1 vote
1 answer
241 views

The following code has a memory leak and I don't understand why there are references to MyObj. run(1) and run(2) are finished, the context is cleared. import asyncio import gc from contextvars import ...
mq7's user avatar
  • 1,329
2 votes
1 answer
375 views

I'm trying to parallelize logs with Queuehandler and Queuelistener in a fastapi application but the contextvars setted on the main thread does not propagate to "_monitor" thread of the ...
Maurício Silva's user avatar
1 vote
3 answers
107 views

I have a scenario where I need to dynamically decorate recursive calls within a function in Python. The key requirement is to achieve this dynamically without modifying the function in the current ...
Michiel Karrenbelt's user avatar
1 vote
1 answer
764 views

In the documentation for the Python standard library module contextvars, it is stated that: Context Variables should be created at the top module level and never within closures. However, I am ...
Fang Hung-chien's user avatar
0 votes
1 answer
219 views

The asyncio.create_server listens on the specified address:port and calls the methods of the supplied callable that implements BaseProtocol. Everything seems fine with the examples provided like this: ...
rugubara's user avatar
-2 votes
1 answer
376 views

When running this code below I got an AttributError: __enter__ I looked around with no success. import contextvars # Création d'une variable de contexte user_context = contextvars.ContextVar("...
Herve Meftah's user avatar
  • 1,085
1 vote
1 answer
748 views

Here is a simple echo server that works correctly as expected - by "correctly" I mean, in the output we see that every user gets its own unique address when echoing inside ...
S.B's user avatar
  • 17k

15 30 50 per page