Skip to content

Instantly share code, notes, and snippets.

View Olamidun's full-sized avatar

Kolapo Opeoluwa Olamidun Olamidun

View GitHub Profile
@Olamidun
Olamidun / threads_with_lock.py
Created September 27, 2023 21:16
Threads with lock
from time import sleep
from threading import Thread, Lock
counter = 10000
lock = Lock() # Instantiate Python thread lock
def decrease_with_thread_locking(by):
global counter
@Olamidun
Olamidun / threads_without_lock.py
Created September 27, 2023 21:08
Race condition without thread locking
from time import sleep
import threading
counter = 10000 # dummy farmer balance in wallet
def decrease_without_thread_locking(by):
global counter
print(f"Initial Balance: {counter}")
local_counter = counter
local_counter -= by # simulate deducting the amount the farmer want to withdraw from the wallet
@Olamidun
Olamidun / slug_sample.py
Last active October 15, 2022 12:25
Sample Slug Code Snippet
class Farmer(models.Model):
#existing fields
slug = models.SlugField(max_length=500, null=True)
def __str__(self):
# The string representation for farmers
pass
# This can also be in the signals