This file contains hidden or 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
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 | |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |