<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Non-Convex Notes</title><link>https://hongyi.sh/tags/python/</link><description>Recent content in Python on Non-Convex Notes</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 23 Jul 2026 23:43:22 -0700</lastBuildDate><atom:link href="https://hongyi.sh/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Producer consumer problem in coroutine</title><link>https://hongyi.sh/posts/2015-03-02-coroutine-producer-comsumer/</link><pubDate>Mon, 02 Mar 2015 00:00:00 +0000</pubDate><guid>https://hongyi.sh/posts/2015-03-02-coroutine-producer-comsumer/</guid><description>&lt;h2 id="what-is-coroutine"&gt;What is coroutine&lt;/h2&gt;
&lt;p&gt;As the name implies, coroutine refers to co-operative routine. It allows you to suspending and resuming execution at different locations. So, it&amp;rsquo;s essentially just context switching. Not surprisingly, coroutine is implemented in primitives like setjmp/longjump or ucontext in low level.&lt;/p&gt;
&lt;p&gt;In many senarioes, coroutine is a more light-weight alternative of threads. For programming languages with GIL (like Python), coroutine would used to handle concurrency.&lt;/p&gt;
&lt;h2 id="producer-and-consumer-problem"&gt;Producer and consumer problem&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s take a look at classic &amp;ldquo;producer-consumer&amp;rdquo; problem. At each time, one coroutine produce products and add them into queue, the other coroutine take products from queue and use it (hmm, sounds like video buffering, right?).&lt;/p&gt;</description></item><item><title>Colorizing Loggers -- A simple practice of decorator</title><link>https://hongyi.sh/posts/2015-02-17-colorize-log/</link><pubDate>Wed, 18 Feb 2015 00:00:00 +0000</pubDate><guid>https://hongyi.sh/posts/2015-02-17-colorize-log/</guid><description>&lt;h2 id="what-is-this-post-about"&gt;What is this post about&lt;/h2&gt;
&lt;p&gt;Many people believe that decorator is one of the obscure concepts in Python.
Trust me, it is not. To be short, &lt;strong&gt;a decorator is a function that modifies other
functions via closures.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;They are plenty detailed articles about what decorator it is so there is no need to write one more. If you are not familiar with it, you may want to check these:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://sahandsaba.com/python-decorators.html"&gt;A Study of Python&amp;rsquo;s More Advanced Features Part II: Closures, Decorators and functools&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>