I have a code that requires that when users type in their input, it is stored in a json file and accessed by some functions. Different users type in their input at different times, in this case the json file is accessed by multiple users as follows:
#post data
for item in mm:
data['questions'].append({'name': item})
with open('my_data_loop.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
#get it
posted = []
with open('my_data_loop.json') as json_file:
data = json.load(json_file)
for p in data['questions']:
posted.append(p['name'])
...process the string
If I have more users concurrently accessing the file, will there be any issue of accessing wrong data at one point? e.g. user 'B' getting info from processed string for user 'A' How can I avoid this and allow one user's iteration to post and process the data to completion?
***I've not used json data extensively, just learning the ropes.