Using contextvars instead of wrapper classes to store additional data

Let's say we have class with data: class Foo: def __init__(self, x, y): self.x = x self.y = y And collection class: class Bar: def __init__(self, foos): self.foos...

How do I write consistent stateful context managers?

EDIT: As pointed out by Thierry Lathuille, PEP567, where ContextVar was introduced, was not designed to address generators (unlike the withdrawn PEP550). Still, the main question remains. How do I...

A way to add typings to contextvars in Python

Is there a way to type out the results when calling the get method on a ContextVar? Something like this from contextvars import ContextVar my_var : ContextVar[MyType] = ContextVar('my_var',...

How to make a Flask application in venv works with Anaconda

I'm trying to start a flask application, with flask run, (which was working fine before I installed Anaconda), and I'm getting the following stack trace Traceback (most recent call last): File...

cannot import pyLDAvis - ModuleNotFoundError: No module named '_contextvars'

I am trying to import pyLDAvis but it gives the error ModuleNotFoundError: No module named '_contextvars' although I installed both pyLDAvis and contextvars. The error is as follows Traceback...

Is a change made to contextvars in a process pool not propagated to the main process running the asyncio loop

Below is the code snippet that I ran: from concurrent.futures import ProcessPoolExecutor import asyncio import contextvars ctx = contextvars.ContextVar('ctx', default=None) pool =...

ContextVars across modules

I am completely newb on asyncio and ContextVars, I just read up what's new in 3.7 and discovered ContextVars, I struggle to understand it's usage, all I know it's helpful in coroutines, instead of...

No module named '_contextvars' in Python 3.7.3 virtual environment

I'm working on a Django project which requires Python3.7.3 virtual environment on Ubuntu 16. So I created a virtual environment and installed all the requirements in it and verified it, activated...

Using Python 3.7 contextvars to pass state between Django views

I'm building a single database/shared schema multi-tenant application using Django 2.2 and Python 3.7. I'm attempting to use the new contextvars api to share the tenant state (an Organization)...

How to translate commands without passing a context. (Discord Bot)

I'm coding a Discord bot. There you define your commands like @commands.command() async def hello(self, ctx): await ctx.send("Hello world!") This would create a command hello, which would...

getting a value from a context by name

I want to use context vars for a similar purpose like in this question and accepted answer: https://stackoverflow.com/questions/50854974/context-variables-in-python That corresponds to f3a() in...

Running PySpark script with dependencies

On a cdh6.2.0 cluster with Spark 2.4.0 and Yarn I'm trying to submit a Python script with PySpark (and in the future I'll need to make Oozie do the submission). Cluster nodes are heterogeneous...

Fetching Context Variables by identifier

I'm trying to use the new contextvars library (https://docs.python.org/3/library/contextvars.html) to make certain values available across modules in an async context, similar to...

Sharing state between two async programs in python using asyncio and contextvars

I currently have two infinite asynchronous tasks running and want to share state between them. One task is a websocket connection that reads in messages then sends messages and the other reads in...

“rasa x" returns AttributeError

I have installed rasa x on my computer. rasa shell works well. I can chat within terminal. but when I try to run rasa x I get following error.I am using python 3.6 and tensorflow backend. Starting...

Understanding Python contextvars

Regarding the following SO answer . I've made some changes in order to understand the difference between do use Contextvars and don't. I expect at some point the variable myid gets corrupted but...

Import Error: Cannot import name 'statfunc' (pymc3 module already installed)

When i try to import pymc3 module on my Jupyter notebook using import pymc3 as pm i get the following error ```ImportError Traceback (most recent call...

Understanding algebraic effects

I came across Effekt language and the idea of algebraic effects. But I'm not sure if I understood the concept correctly. I tried to re-implement the basic "hello world" example in Python and came...

Colab running Pennylane with DeviceError

I tried to run Pennylane on Colab, so I install it first. But the "Installed devices" are null, what's going on? I have restart and rebuilt for several times. Here is my code. !pip install...

Correct way of using AsyncMachine and multiple objects in transitions

i'm trying to implement client-server application via websockets and i have several doubts how to do it correctly to maintain state of every connected client. global machine + many objects for...

Python Django ModuleNotFoundError for modules containing underscores only on CI pipeline

I have been hitting the ModuleNotFoundError error when I add modules to my project in the requirements.txt file. This seems to only occur with module imports that have an underscore. Namely these...

How to use FastAPI and Psycopg2 without ORM?

I have a project with FastAPI but I don't want to use SQLAlchemy or another ORM because I think it's not necessary to install extra dependencies for my queries, these are a simple SELECT. I have...

What happens if I don't reset Python's ContextVars?

Is this a memory leak in Python? import contextvars contextvar = contextvars.ContextVar('example') while True: string = 'hello world' token = contextvar.set(string) Is a contextvar a...

Jupyter Notebook Cannot Connect to Kernel, Likely due to Zipline / AssertionError

All of my virtual environments work fine, except for one in which the jupyter notebook won't connect for kernel. This environment has Zipline in it, so I expect there is some dependency that is a...

Python `from module import name` vs `import module`

Why this doesn't work: >>> import structlog >>> structlog.contextvars.bind_contextvars() AttributeError: module 'structlog' has no attribute 'contextvars' >>> But this does: >>> from...

Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway

I try to use library cv2 for changing picture. In mode debug I found out that problem in function cv2.namedWindow: def run(self): name_of_window = 'Test_version' image_cv2 =...