Python
Asyncio By Example: Implementing the Producer-Consumer Pattern
python coroutine techThe Most Basic Case
With corountines, we can define a produer and consumer without any need for threads. This simplifies our code and makes it more efficient.
import asyncio
async def producer():
for i in range(6):
await asyncio.sleep(0.2)
yield i
async def consumer():
async for i in producer():
print(i)
async def main():
await asyncio.gather(consumer())
asyncio.run(main())
0
1
2
3
4
5
Work with Heavy IO
When working with heavy IO operations, we need to be careful not to block the event loop. Running heavy IO operations can block the current event loop, which would slow down the scheduling of all coroutines.
Emacs Lisp Introduction for Python Programmers
emacs lisp tech pythonThis is a brief introduction to Emacs Lisp for Python programmers, (although I am not an Elisp expert, and actually I am more familiar with Python than Elisp). Both languages have quite different syntaxes, it is interesting to see how can implement Python code with lisp code.
The content follows the strucutre from Learn X in Y Minutes Where X is Python, and we will touch all the topics.
Primitive Datatypes and Operators
Numbers
Python
| Elisp
|
Bools and comparasion
In Emacs Lisp, booleans are represented by the symbols t
for true and nil
for false.
Best Practices for Python Programming (Continuously Updated)
python techWhen delving into the codebases of some successful large Python projects such as PyTorch, I am consistently impressed by their code – whether it’s clean yet precise, or leveraging lesser-known built-in or third-party packages to significantly enhance functionality.
High-quality code snippets, handy packages, and modules have greatly facilitated my work. In this blog, I’ll be sharing noteworthy findings and insights learned from the open-source codebase.