MarcoParola's picture
implement user space, counter system to assign ad id to each user
8092894
Raw
History Blame Contribute Delete
529 Bytes
import os
import pandas as pd
from threading import Lock
class UserID:
def __init__(self):
self.lock = Lock()
self.counter = 0
if os.path.exists('global_variable.csv'):
df = pd.read_csv('global_variable.csv')
self.counter = df['value'][0]
def increment(self):
with self.lock:
self.counter += 1
df = pd.DataFrame({'value': [self.counter]})
df.to_csv('global_variable.csv', index=False)
return self.counter