I am using a python socketio async server. I have several socketio.on processes that can occur in my backend. Each user in my website can send a socket to the backend and execute their own process however, in my terminal, each users process is executing one at a time.
For example:
socketio=sio.AsyncServer(cors_allowed_origins="*")
app = web.Application()
socketio.attach(app)
def trainmodel(x, y, username,code):
******Over here training the users AI model which takes about 10 seconds to do
args = TrainingArguments(
output_dir="output",
num_train_epochs=10,
per_device_train_batch_size=10,
optim = "adamw_torch"
)
trainer = Trainer(
model=model,
args=args,
train_dataset=train_dataset,
#eval_dataset=val_dataset,
compute_metrics=compute_metrics
)
trainer.train()
@socketio.on("sendbackends")
async def trainit(sid,data,code):
trainmodel(x,y,username,code)
@socketio.on("bottoken")
async def handle():
await socketio.emit("redirect",namespace = "/")
if __name__ =='__main__':
web.run_app(app, port=5000)
my socket.on functions are running one at a time, however I want every process to run in parallel where it doesnt block the next processes.