Restart Gurobi Compute Server job with python code after status 502
Awaiting user inputI'm hosting a small python web app via Jupyter + Docker on a Linux server, and it has a Gurobi backend set up and connected to the Compute Server via an Instant Cloud license.
The solver was working fine when I initially started the but showed this error message "GurobiError: Unexpected response (status 502, command PUT https://...... )" after a while. I believe the Compute Server job automatically stopped after a period of time. Is there a way to catch this error and restart it via python code instead of having to restart the docker container every time this happens? Thanks a lot!
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
-
Hi Hancheng,
You can implement a retry mechanism using a try-except block. Something like:
try:
model.optimize()
except gp.GurobiError as e:
error_message = str(e)
if "status 502" in error_message:
print("Retrying due to 502")
model.optimize()However, this only retries to optimize the model once. Setting up a retry limit can mitigate this.
Regards,
Alex0 -
Hi Alex. Thanks for the response, but I don't think it solves the issue, as the code is failing at model creation when it initially communicates with the Compute Server. I think it's gone into idle shutdown after 60 minutes per the Instant Cloud documentation
model = gp.Model("model_name")If I put a try-except here, the except needs to be some command that wakes up the server from idle
0 -
Hi Hancheng,
Since you are using Instant Cloud, can you provide me the Job ID so I can check the logs?
Regards,
Alex0
Post is closed for comments.
Comments
4 comments