Can Someone Review My Python Async/Await Blog Post?

0
0
Asked By CuriousCat123 On

Hey everyone! I noticed that a lot of my coworkers aren't quite grasping the concept of `async` and `await`, so I decided to write a blog post diving deeper into these topics. Since Python isn't my primary programming language, I'd love for someone who really knows their stuff about async/await, Awaitable, and coroutines in Python to check it over and provide feedback. Here's the link to my post if you're interested: [Blog Post](https://yoric.github.io/post/quite-a-few-words-about-async/). Thanks a ton!

2 Answers

Answered By CodeNinja_42 On

Overall, I think your post looks pretty solid, but there are a few technical corrections to make:

1. In your function's return type hint, it should be `def fibonacci(n: int) -> int:` instead of `def fibonacci(n: int): int`.

2. When dealing with threading, remember to use `start()` instead of `run()`. The code block where you create a thread should look something like this:

```python
import threading

def on_event(event):
if isinstance(event, ComputeFibonacciEvent):
def background():
result = fibonacci(event.arg)
print(f"fibonacci({event.arg})={result}")
thread = threading.Thread(target=background)
thread.start()
else:
...
```

3. I noticed you used `parent` instead of `parent_id`. Just a little fix.

CuriousCat123 -

Thanks for pointing those out! I’ll make those adjustments right away.

Answered By TechWhiz_89 On

I didn’t spot any major factual mistakes, but I think the post can be clearer about why we're using async/await. You mention latency early on, but it's important to address that the overhead of OS threads is a big factor too. Maybe you could contrast the pros and cons between using event loops, threads, and processes, particularly touching on the Python GIL and how that affects performance. Plus, you might consider mentioning greenthreading, especially since it’s relevant in other languages like Golang.

Also, I found a fantastic talk on concurrency trade-offs in various languages that might inspire some content: [Watch here](https://www.youtube.com/watch?v=lJ3NC-R3gSI).

Oh, and just a heads up: there’s a bit about writing thread-safe code that may mislead some readers into thinking Python doesn’t struggle with this issue. Native libs can release the GIL, which could lead to execution order issues if you're not careful with threading.

CuriousCat123 -

Thanks for your thoughts! I definitely need to emphasize the downsides of context-switching and locks more. I have a section on threads and the GIL but I’ll make sure to expand on it. Regarding greenthreading, I understand your point there—it's not featured prominently in my post right now; I’ll work on giving it more context.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.