How do I auto reconnect on disconnect?
See original GitHub issueI’m trying to call ib_insync.Client.connect(…) in a loop with a delay in wrapper.apiEnd and got an exception
RuntimeWarning:
coroutine ‘Client.connectAsync’ was never awaited`
Is this the correct way to reconnect? Or do I need to del my client instance and create a new one?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Turning Auto Reconnect On or Off on Mobile Devices - Webroot
Tap Auto Reconnect. In the Auto Reconnect area, do either of the following: Tap the slider to the left to turn Auto Reconnect...
Read more >Is there a way to auto-disconnect and reconnect WiFi ... - Quora
However, providing devices are set to auto-connect, simply reboot the router and devices will be disconnected and can reconnect automatically as the router ......
Read more >How to get computer to reconnect automatically after ...
Make your connection as your default internet connection. Open Network Connection in Control Panel. Right click your Internet connection and ...
Read more >Auto-disconnect and auto-reconnect
The auto-reconnect process ensures that any connections that were auto-disconnected are automatically reconnected. Then, if configured, Double-Take Availability ...
Read more >Enabling Server Auto-reconnect - Micro Focus
This opens the Configure Server dialog box. Select the General tab. Check Reconnect timeout. Type the number of minutes in the text box...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for commenting on a closed issue, but I wanted to share a solution.
If peer closes connection (TWS being shutdown), you can catch this using the
disconnectedEvent
. Then you will need to break the run loop. Instead of dealing with async, I use a simple SIGINT signal for this. The program also needs to know whether if we are restarting due to a disconnect issue, or the user just wants to stop the program. This is why I set a class variable called reconnecting to True if our SIGINT’s intention is to reconnect. This way, we know if we want to stop retrying and exit to program.If TWS loses connection to internet temporarily, then reconnects to market data (errorCode = 1102), we need to handle this inside
errorEvent
. I just set reconnecting to True, calldisconnect()
and raise SIGINT. If you dont’ disconnect, reconnect will not succeed due to clientId = 1 still connected.If we lose connection to TWS due to API being disabled (errorCode = 1300) we need to set reconnecting to True, call
disconnect()
(might not be needed but it is idempotent) and raise SIGINT.After doing all of this, there is still a problem. If I login from another computer, then logout, we still need to manually click the “Reconnect this session” button of the modal dialog that appears in the TWS application.
The assert is only hit in the case of nested event loops. To allow nested event loops, use util.patchAsyncio().