You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Context variables shared between code don't work with greenlet > 0.4.17 #852
greenlet 0.4.17 introduced support for ContextVars.
It seems the result of this, is that the following code no longer works in bpython:
>>> import contextvars
>>> help = contextvars.ContextVar("helpme")
>>> token = help.set("value")
>>> help.reset(token)
Traceback (most recent call last):
File "<input>", line 1, in <module>
help.reset(token)
ValueError: <Token var=<ContextVar name='helpme' at 0x10f84b770> at 0x10f603940> was created in a different Context
The workaround is to put all this code in a single function
I believe this might be caused because a new greenlet is created for each line of code in bpython.
Is it possible for everything to run in the same context so that the repl behaviors similar to how a python script would run?
I'd like to throw my support behind finding a solution to this without requiring code to be kept as a single "execution block" (as per the above workaround).
I'm using bpython as an interactive REPL mostly for hand debugging / testing code during development, so being able to write and evaluate different blocks of code and inspecting the various results whilst maintaining the overall context is important to me.
I'll note that although this issue is tagged with requires-separate-process it may be possible to resolve it whilst continuing to use greenlet - https://greenlet.readthedocs.io/en/latest/contextvars.html (which may be overall less work, but also I'm not super familiar with greenlet or bpython so could be completely wrong).
Activity
nhairs commentedon Oct 20, 2023
I'd like to throw my support behind finding a solution to this without requiring code to be kept as a single "execution block" (as per the above workaround).
I'm using bpython as an interactive REPL mostly for hand debugging / testing code during development, so being able to write and evaluate different blocks of code and inspecting the various results whilst maintaining the overall context is important to me.
I'll note that although this issue is tagged with
requires-separate-processit may be possible to resolve it whilst continuing to usegreenlet- https://greenlet.readthedocs.io/en/latest/contextvars.html (which may be overall less work, but also I'm not super familiar with greenlet or bpython so could be completely wrong).fix: Context variables shared between code don't work with greenl (bp…
fix: Context variables shared between code don't work with greenl (#852)