Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
How to make a thread to make 100 concurrent request to db in Python ?

I want to simulate 120 people booking 120 seats all at once, how should I do that!!

This is what I am doing for the same

for i in range(120):
thread = Thread(target=book, args=(GetUser(i),)).start()
thread.join()

This is what my book function looks like:

def book(user): #user -> airline.User, seat -> airline.Seat
print(user1 + "with id " + str(user0) + " trying to book seat ")
seats = availableseats()
print("Total Available seats: " + str(seats[0]))

#selecting the seat at random
seat = random.randint(1, seats[0])
seat = GetSeat(seat)
print("Seat selected: " + str(seat[1]))
mycursor.execute("UPDATE seats SET USER
ID = " + str(user0) + " WHERE id = " + str(seat0))
mydb.commit()

But with this approach I am getting 2

/r/django
https://redd.it/ywqm7a