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 USERID = " + str(user0) + " WHERE id = " + str(seat0))
mydb.commit()
But with this approach I am getting 2
/r/django
https://redd.it/ywqm7a
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 USERID = " + str(user0) + " WHERE id = " + str(seat0))
mydb.commit()
But with this approach I am getting 2
/r/django
https://redd.it/ywqm7a
reddit
How to make a thread to make 100 concurrent request to db in Python ?
Posted in r/django by u/suraj_78797 • 9 points and 12 comments