question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set global variable in request lifecycle?

See original GitHub issue

How can I set some data in global request lifecycle which can be used throughout the app In flask, it was possible via,

from flask import g
g.data  = {}

tried setting data to the incoming requests, but it turns out request is read-only. Please help! Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
glenfantcommented, Aug 1, 2020

Hi @knowBalpreet and other contributors of this issue.

I just learned the new contextvars that comes with Python 3.7+, and made this Gist that provide a request lifecycle pseudo-global similar to the Flask “g” object.

https://gist.github.com/glenfant/2fe530e5a2b90c28608165b5a18afcaf

Any comment on the Gist is welcome.

8reactions
jessewilescommented, May 25, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

FastApi: How to define a global variable once - Stack Overflow
One approach would be to use the FastAPI startup event to define the variable data once on app startup. An example similar to...
Read more >
How to set a global variable in Postman? - Tutorialspoint
Step4 − First select the option Environment_Test and add {{url} in the address bar. On hovering over it, we shall show the letter...
Read more >
How do I set global variables to be used by all flows? - IBM
In IBM Spectrum LSF Application Center, select System & Settings > System Services > Flow Manager Service; Select Set Global Variables to display...
Read more >
Can we use global variable sets in different applications
Yes, We can use Global variable sets in different application Record producer. The scripts and policies which are applicable to that global ...
Read more >
Use Global Variables and Data Stitch to log request payloads
We will create a Global Variable based on the request payload. Global Variables are visible anywhere in the integration, including fault ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found