Skip to content

IPykernel >= 7.0.0 ContextVar values are not preserved between cells #1457

@RRRajput

Description

@RRRajput

If a value is assigned to a contextvar, it will not be preserved when moving to another cell in the notebook.
See this short example:

# cell 1
from contextvars import ContextVar

bro = ContextVar("bro", default="thisismydefaultvalue")
bro.get()
>> 'thisismydefaultvalue'
# cell 2
bro.set("!!!!!!!!!!!MODIFIED!!!!!!!")
bro.get()
>> '!!!!!!!!!!!MODIFIED!!!!!!!'
# cell 3
bro.get()
>> 'thisismydefaultvalue'

I've verified that this issue does not occur for ipykernel<7.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions