generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: real python - thread safety tutorial
- Loading branch information
1 parent
d48d160
commit d01ef6a
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: Thread Safety in Python - My first tutorial for Real Python | ||
date: 2024-10-24 18:00:00 +05:30 | ||
categories: [ Python, threading ] | ||
tags: [ python, threading ] # TAG names should always be lowercase | ||
--- | ||
|
||
My first tutorial for Real Python got published 🎉 | ||
|
||
"Python Thread Safety: Using a Lock and Other Techniques": [https://realpython.com/python-thread-lock/](https://realpython.com/python-thread-lock/) | ||
|
||
### Why thread safety? | ||
|
||
Below is a classic example of creating a singleton class is Python: | ||
|
||
```python | ||
class SingletonClass(object): | ||
def __new__(cls): | ||
if not hasattr(cls, 'instance'): | ||
cls.instance = super(SingletonClass, cls).__new__(cls) | ||
return cls.instance | ||
``` | ||
|
||
The SingleTonClass is supposed to have only 1 object, but the code can lead to the creation of more than one instances | ||
when executed in a multithreaded environment. | ||
|
||
Read the tutorial to spot such race conditions and learn to fix them using Python's synchronization primitives. | ||
|
||
Read now at Real Python Website: [https://realpython.com/python-thread-lock/](https://realpython.com/python-thread-lock/) | ||
|
||
--- | ||
--- | ||
|
||
I share interesting Python snippets from open-source projects illustrating Python language features in my | ||
newsletter, "Python in the Wild". | ||
|
||
Subscribe to the newsletter on [Substack](https://adarshd.substack.com/) | ||
or [Linkedin](https://www.linkedin.com/newsletters/python-in-the-wild-7155981512197181440/) to receive new Pythonic | ||
posts to your email 💌🚀. |