Title: Context variables shared between code don't work with greenlet > 0.4.17 · Issue #852 · bpython/bpython · GitHub
Open Graph Title: Context variables shared between code don't work with greenlet > 0.4.17 · Issue #852 · bpython/bpython
X Title: Context variables shared between code don't work with greenlet > 0.4.17 · Issue #852 · bpython/bpython
Description: 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") >>> ...
Open Graph Description: 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("hel...
X Description: 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 = contextva...
Opengraph URL: https://github.com/bpython/bpython/issues/852
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Context variables shared between code don't work with greenlet > 0.4.17","articleBody":"greenlet 0.4.17 introduced support for [ContextVars](https://github.com/python-greenlet/greenlet/blob/master/CHANGES.rst#0417-2020-09-22). \r\n\r\nIt seems the result of this, is that the following code no longer works in bpython:\r\n\r\n```\r\n>>> import contextvars\r\n>>> help = contextvars.ContextVar(\"helpme\")\r\n>>> token = help.set(\"value\")\r\n>>> help.reset(token)\r\nTraceback (most recent call last):\r\n File \"\u003cinput>\", line 1, in \u003cmodule>\r\n help.reset(token)\r\nValueError: \u003cToken var=\u003cContextVar name='helpme' at 0x10f84b770> at 0x10f603940> was created in a different Context\r\n```\r\n\r\nThe workaround is to put all this code in a single function\r\n\r\n```\r\n>>> def do_the_stuff():\r\n... help = contextvars.ContextVar(\"helpme\")\r\n... token = help.set(\"value\")\r\n... help.reset(token)\r\n... \r\n... \r\n>>> do_the_stuff()\r\n```\r\n\r\nI believe this might be caused because a [new greenlet is created](https://github.com/bpython/bpython/blob/3ae9b1084d4abf688d2ff659d4fbf96131029148/bpython/curtsiesfrontend/coderunner.py#L137) for each line of code in bpython. \r\nIs it possible for everything to run in the same context so that the repl behaviors similar to how a python script would run?\r\n","author":{"url":"https://github.com/c-py","@type":"Person","name":"c-py"},"datePublished":"2020-10-06T06:40:19Z","url":"https://github.com/bpython/bpython/issues/852"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b0dd7e48-9a54-83a7-fb63-e182d0ef7f07 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBEA:3F8AB1:3F3613E:5041013:6B01FC93 |
| html-safe-nonce | 35f81be25dd8084ea431bf0ae27ab440f1e1c37caeec2d19c2b37ef513802a12 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkVBOjNGOEFCMTozRjM2MTNFOjUwNDEwMTM6NkIwMUZDOTMiLCJ2aXNpdG9yX2lkIjoiMzM0MTM0NzE1Nzc4NDUyNTk3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 82cf2064c6b87e2bc491c5caf6b16e7a2ba7f80bb9bd1ccdbbd5a4391048ed4c |
| hovercard-subject-tag | issue:715391203 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/bpython/bpython/852/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1bffdbfce57aee4857d220b7fab1e6d9cfa4be26f9a9471e6dcd28fd19d09260/bpython/bpython/issues/852 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1bffdbfce57aee4857d220b7fab1e6d9cfa4be26f9a9471e6dcd28fd19d09260/bpython/bpython/issues/852 |
| og:image:alt | 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("hel... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | c-py |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/bpython/bpython git https://github.com/bpython/bpython.git |
| octolytics-dimension-user_id | 8071396 |
| octolytics-dimension-user_login | bpython |
| octolytics-dimension-repository_id | 21508865 |
| octolytics-dimension-repository_nwo | bpython/bpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21508865 |
| octolytics-dimension-repository_network_root_nwo | bpython/bpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width