Python Forum
Reconnect to an API? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Reconnect to an API? (/thread-33078.html)



Reconnect to an API? - stylingpat - Mar-27-2021

Hello everyone, my Python program connects to an API, is there any way to make it try and "auto reconnect" every 1 min to the said API if it gets disconnected?

My connection code is on a single thread.. so mechanically, I would need a way to just:

1. detect a disconnect, and
2. IF disconnect found, do a while loop on the thread.start()
3. untill connection restored?

This should be an interesting discussion and hopefully I learn alot from it but I am still pretty new, so simple explanations and code examples are the best Pray


RE: Reconnect to an API? - stylingpat - Mar-27-2021

So after some head aching searching, it seems the easiest way to do this is to have a totally separate script monitoring some type of connection, if the connection goes out, close the original script and re-run the original script after connection is restablished?