How can I timeout an attempt to connect to SQL Server using sqlalchemy?

Asked

Viewed 42 times

2

I have a list of 200 hosts to connect. The problem is that when I try to connect to a host that is not available, it takes about 10 seconds for me to receive an exception telling me that I have not connected. But when connected it takes less than 1 second to connect.

I wanted something like this:

if(engine.connect() > 1 segundo) para de tentar conectar

I tried to

 create_engine(db_url, connect_args={'connect_timeout': 1})

Didn’t work.

I am using sqlachemy, trying to connect on SQL Server

Thank you

  • Please translate your question. You are at stackoverflow

1 answer

1

To SQL Server the correct parameter is Remote Query Timeout

create_engine(db_url, connect_args={'Remote Query Timeout': 1})
  • I tried this, but now error in all connections with the exception "Remote Query Timeout" :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.