erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.86k stars 778 forks source link

watchdog.stop / IBC.terminate error #117

Closed charlesedwards closed 5 years ago

charlesedwards commented 5 years ago

Hi,

I cannot get IB TWS to shutdown with ib_insync IBC or Watchdog. after the app.stop() or ibc.terminate() statement, the script just sits there and never ends. the TWS platform does not shut down.

My code:

asyncio.set_event_loop(asyncio.ProactorEventLoop())
ibc = ib_insync.IBC(twsVersion=974,
                 gateway=False,
                 tradingMode='live',
                 ibcIni=r'C:\Users\Administrator\Documents\IBC\config.ini',
                 ibcPath='C:\IBC',
                 twsPath='C:\Jts')

ibc.start()
ib = ib_insync.IB()
ib.sleep(100)
ib.connect('127.0.0.1', 7496, clientId=77)

print('do something')

ib.disconnect()
ibc.terminate()

The IB log after start up:

2018-12-14 18:27:59 Synchronization complete
2018-12-14 18:28:00 Disconnecting from 127.0.0.1:7496, 598 B sent in 7 messages, 20.2 kB received in 420 messages, session time 101 s.
2018-12-14 18:28:00 disconnecting
2018-12-14 18:28:00 Disconnected
2018-12-14 18:28:00 ANSWER connectionClosed {}
2018-12-14 18:28:00 Terminating

after that last terminating message, the script just sits there and nothing happens. IB never closes.

I have the same result when trying to use watchdog instead.

How can I fix this so IB TWS closes and the script ends?

Thanks

erdewit commented 5 years ago

It works for me (on Linux). It'll be a while before I can try this out on Windows.

charlesedwards commented 5 years ago

Yep I am on Windows

erdewit commented 5 years ago

The issue was that on windows terminating the IBC process did not terminate the TWS/gateway child process. The taskkill windows command is now used to terminate the whole lot.