Race Condition and How to Solve it - threading.Lock() | 2MinutesPy

  Рет қаралды 1,791

2MinutesPy

2MinutesPy

3 ай бұрын

#racecondition #concurrency #threading #threads #python #pythonprogramming #2minutespy
🖐Hey, have you ever heard of "race condition"?
Race condition?? What is that? You might ask the same question, don't worry, in this video, we'll see the race condition and how to solve it.
Race condition occurs when we run concurrent or multi-threaded programs as they access shared resources simultaneously leading to unpredictable/inconsistent results.
We can solve it using the threading.Lock() that restricts multiple threads to access shared resources simultaneously.
More 2 Minutes Python Tutorial:
What are these (/ and *) parameters in function? • What are these (/ and ...
How to create a MySQL DB in Python: • Create a MySQL Databas...
Yield Keyword in Python: • Python Yield Keyword??...
Class in Python: • How to Create a Class ...
Decorators in Python: • What are Decorators in...
List comprehension in Python: • How to use list compre...
How to use map() in Python: • How to use map() funct...
reverse() vs. reversed() in Python: • Python's reverse() Vs ...
Why Flask(__name__) is Used When Creating a Flask App? • Why Flask(__name__) is...
What is Global Interpreter Lock in Python? • Global Interpreter Loc...
What is a Lambda Function in Python? • What is a Lambda Funct...
Why __init__.py File is Used in Python Projects: • Why __init__.py File i...
if _name_ == "__main__" in Python: • What if __name__ == '_...
Python's seek() and tell() functions in 2 Minutes: • Understanding Python's...
- Python Threading in 2 Minutes: • Python Threading in 2 ...
- Python's super() function in 2 Minutes: • Python's super() Funct...
- How to Use *args and **kwargs in 2 Minutes: • How to Use *args and *...
- Python's ABC (Abstract Base Class) in 2 Minutes: • Python's ABC (Abstract...
- Python's _init_ Method in 2 Minutes: • Python's __init__ Meth...
Python's _getitem_ Method in 2 Minutes: • Python's __getitem__ M...
Subscribe to / @2minutespy for more such videos.
@2MinutesPy

Пікірлер: 10
@champfisk5613
@champfisk5613 3 ай бұрын
Now this is practical and good
@2MinutesPy
@2MinutesPy 3 ай бұрын
Thanks
@sachinpal5823
@sachinpal5823 3 ай бұрын
Nice topic🎉
@2MinutesPy
@2MinutesPy 3 ай бұрын
Thanks 😊
@cyberlando
@cyberlando 3 ай бұрын
I remember reading in a book that you can parallelize work in python like that …. Python doesn’t have true multithreading capabilities isn’t that correct ?
@2MinutesPy
@2MinutesPy 3 ай бұрын
Yeah, it's right and all of this because of GIL but still you can perform parallelize task
@KasimAhmic
@KasimAhmic 3 ай бұрын
Python’s threading module allows you to run many tasks in parallel, but with only one of those tasks being executed at a time. Python handles switching between the tasks whenever there is “downtime” within the tasks. This downtime usually comes in the form of IO operations like reading/writing to a file, making network requests, etc. What Python can do is pause execution of one task that is already waiting for the OS to finish writing to a file (for example), and resume execution of another task that isn’t waiting on anything. Now if each task is doing something synchronous or CPU intensive, say encryption/decryption, Python’s threading module will give you no benefit whatsoever as each task will block the next until it is done with the encryption/decryption. In this case, there is no downtime and Python is unable to pause/resume execution of the tasks. To combat this limitation, Python also has the multiprocessing module which allows you to spawn separate Python interpreters in completely separate processes and enables communication between said processes. This allows you to run as many tasks as your computer can handle (usually limited by core count) with all of them executing simultaneously at the cost of increased CPU and memory usage. As a general rule of thumb, if you have an IO heavy application (i.e. one that spends most of its time idle, waiting on external systems) the threading module is for you. On the other hand, if you have a largely synchronous application where you spend most of your time executing Python code, multiprocessing is the way to speed things up.
@2MinutesPy
@2MinutesPy 3 ай бұрын
Great, that's some valuable info
@FeverYonge
@FeverYonge 3 ай бұрын
Make a video about concurrent.future use for accessing (login and do stuff) multiple network devices at same time, without waiting for the first task to finish
@2MinutesPy
@2MinutesPy 3 ай бұрын
Yeah, sure
Python Yield Keyword?? 2MinutesPy
1:56
2MinutesPy
Рет қаралды 2,1 М.
No JS, Async/Await in Python - asyncio
2:03
2MinutesPy
Рет қаралды 1,2 М.
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 55 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 56 МЛН
Introduction to Thread Locks in Python - Part#1
14:02
CodersLegacy
Рет қаралды 1,6 М.
Intermediate SQL -  Filtering grouped data
3:07
Code Path
Рет қаралды 8
How to use the Arduino map function Part 2
6:31
Circuit Crush
Рет қаралды 2,5 М.
HTMX Explained: Build Dynamic Web Pages with Less JavaScript
2:19
How to achieve Concurrency in Python?
1:54
2MinutesPy
Рет қаралды 1,6 М.
python is removing the GIL! (PEP 703) (advanced) anthony explains #550
24:04
__new__ VS __init__ in Python
2:35
2MinutesPy
Рет қаралды 4 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 6 МЛН
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 25 МЛН
ГОСЗАКУПОЧНЫЙ ПК за 10 тысяч рублей
36:28
Ремонтяш
Рет қаралды 75 М.