<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Context Variables on Nalar</title>
    <link>https://nalar.dev/tags/context-variables/</link>
    <description>Recent content in Context Variables on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 08 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/context-variables/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Keep Request State Local with Python contextvars</title>
      <link>https://nalar.dev/keep-request-state-local-with-contextvars/</link>
      <pubDate>Tue, 08 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/keep-request-state-local-with-contextvars/</guid>
      <description>&lt;p&gt;Passing a request ID through every function is explicit, but after a few layers it can become noise. Logging is the example I keep running into: the logger needs the request ID, while most business functions do not actually care about it.&lt;/p&gt;&#xA;&lt;p&gt;A global variable looks tempting until two requests run concurrently. &lt;code&gt;threading.local()&lt;/code&gt; fixes a different problem, but one event-loop thread can execute many asyncio tasks. Python&amp;rsquo;s &lt;code&gt;contextvars&lt;/code&gt; module is designed for this kind of context-local state.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
