Skip to content

Instantly share code, notes, and snippets.

@cengizhancaliskan
Created May 24, 2022 12:29
Show Gist options
  • Save cengizhancaliskan/c112ea95f16a2b1577c3242f836cb4e6 to your computer and use it in GitHub Desktop.
Save cengizhancaliskan/c112ea95f16a2b1577c3242f836cb4e6 to your computer and use it in GitHub Desktop.
ThreadSafeCounter python
# -*- coding: utf-8 -*-
import threading
class ThreadSafeCounter:
def __init__(self, counter=0, max_counter=0):
self.lock = threading.Lock()
self.counter = counter
self.max_counter = max_counter
def get(self):
return self.counter
def set(self, count):
self.counter = count
def incr(self, count=1):
with self.lock:
self.counter += count
def get_max(self):
return self.max_counter
def set_max(self, count):
self.max_counter = count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment